Master Data Structures & Algorithms For FREE at AlgoMap.io!
@TJ-jh6xx4 күн бұрын
Clean solution, thanks! As an improvement, I think you can skip the reverse step completely if you just use insert instead of append: array.insert(0,value). So, basically insert at the front of the array each time instead of append which inserts at the end, requiring the reverse later.
@docsmate2umass19 күн бұрын
simple and clear explanation makes this video more valuable .
@BigStupidTech5 ай бұрын
Spitting straight value. Thanks for these
@GregHogg5 ай бұрын
It's what I do
@Schadenfreude59617 күн бұрын
I like to watch your videos non-decreasing order
@Za3DoRzXАй бұрын
I love your explanations Greg, keep up the good work.
@majestif5 ай бұрын
Many thanks for a great explanation!
@GregHogg5 ай бұрын
You're very welcome 🥰
@christianjt70185 ай бұрын
Great explanation, thanks a lot for sharing
@leandrormor5 ай бұрын
Thanks, your content is brilliant. I hope you'll touch monotonic stack, double heap, prefix sum...
@nurbekmalikov34672 ай бұрын
for space comp just create one iteration index like => iterator = len(num) -1 and every greater value puts original array which is num and iterator-- this is O(1) space!
@MrTo122322 күн бұрын
Hi greg can I just change th3 conditions to append the smallest of the squares of the left and right pointers?
@helloworldcsofficialАй бұрын
Thanks! Will there be more easy and medium problems where we can I apply the two pointer (indices) technique?
@RaviPrakash-dz9fmКүн бұрын
Is this good? from typing import List def squares(array : List[int]) -> List[int]: n = len(array) l = 0 r = n - 1 for i in range(len(array)): array[i] = array[i]**2 while l < r: start = array[l] end = array[r] if end < start: array[l] , array[r] = array[r] , array[l] r -= 1 return array squares([-4, -1, 0, 3, 10]) I tried not to use extra space. I am just learning so I might have missed some edge case
@ryanlalliss59775 ай бұрын
Sorry if this is stupid but why not use the insert method instead of append rather than reverse the array at the end?
@GregHogg5 ай бұрын
That will be inefficient because inserting at beginning is slow
@izzya12824 ай бұрын
Perfectooo amigo
@timkvernen48525 ай бұрын
It's not accurate to say that the biggest values are on the outside. The second biggest value could be the second or second-to-last element. It would be accurate to say that the biggest value will always be on the outside.
@abodora5325 ай бұрын
hmm, but what if they weren't in non decreasing order