Squares of a Sorted Array - Leetcode 977 - 2 Pointers (Python)

preview_player
Показать описание


Please check my playlists for free DSA problem solutions:

My Favorite Courses:

Data Structures & Algorithms:

Python:

Web Dev / Full Stack:

Cloud Development:

Game Development:

SQL & Data Science:

Machine Learning & AI:
Рекомендации по теме
Комментарии
Автор

Master Data Structures & Algorithms For FREE at AlgoMap.io!

GregHogg
Автор

Dude your free DSA pathway has been insanely helpful to me for staying organized and learning proper techniques for the type of data given. Can't thank you enough for putting it out there.

robertedwards
Автор

What if you would initialize the array to the length of the input and fill in the values from last to first, then you would not have to do the flip. Just use L and R to index the array with output values.

arpeggio
Автор

For space complexity, even though the mem space is required, that doesn't abrogate the counting of it. Like, at a store, it is required that I pay money for items. I still have to account for that spending. I am totally cool with being wrong here, this isn't a arguing comment.

askholia
Автор

u could initialize the response array with same size as the inp
have a resPointer var that points to the n-1 index of the response array
compare the abs(R) with abs(L) and the bigger goes to the resPointer and decrease the resPointer
this will ignore the additional loop of the flipping the result array

fadygamilmahrousmasoud
Автор

Thank you so much man.. U r vidoes are really helping me a lot..

jujarusreenivasaraoracdjdp
Автор

I would definitely say the space complexity is O(n). For a problem like this O(1) space complexity would imply it is an in-place transformation.

daveagill
Автор

is using reverse() better than simply returning result[::-1], or would that give the wrong solution?

atharvaranade
Автор

Hey greg, can you please explain to me why this not work the same if we tried to take the smallest value in the comparison? is it because the original array is ordered?

CarlosBenner
Автор

I think you have not sorted data or am i missing something?

ajitsingh
Автор

If your concern is optimising for speed, why are you using Python?

FlyGamingChannel