2 Pointer Algorithm Question Asked by Google! | Squares of Sorted Array - Leetcode 977

preview_player
Показать описание
leetcode, coding, programming, coding interview, software engineer, data, structures, algorithms
Рекомендации по теме
Комментарии
Автор

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

GregHogg
Автор

Big brain:

def squareSortedArray(arr):
return sorted(list(map(lambda n: n ** 2, arr)))

quokka_yt
Автор

My mind went to heap right away, but this the most elegant and better runtime. Cheers!

RS-fzps
Автор

Cool technique. Didn't expect this method to appear here

artinzareie
Автор

There are so many easier ways to do this that don't care about order or left/right.

evlredsun
Автор

Probably better to just first define the array's length as [0] * n and having an idx tracker instead of making python add memory to the array

hidude
Автор

Just create an empty list, using for loop iterate the numbers then square it and then append to that list, then sort it

logeshwaranvivek
Автор

What I immediately came up with was going from left to right, you would add the square of each number to array1 if it’s positive, and the square of the number to array2 if it’s negative. This takes O(n) time. Then you merge these 2 arrays and return that which also takes O(n) time. It’s got a linear space complexity as well.

rkidy
Автор

you could just use a for loop to square each number, append to a placeholder list, then use the sort method to sort the list...why do you need to use 2 pointers???

mazx
Автор

Why not just sort the list first and then square each element?

dhaval
Автор

Sir i love your vidoes .and the way you expalin problems that no other have done ..
Can i ask you which company you work for ?
Thank u sir ❤️❤️❤️

rnniloyiii
Автор

Just explain the algorithm, when we have to understand from the code it is difficult in such a short time but the algo can be understood

abdfn
Автор

Couldn't you just do sort(list) and a for loop to iterate over each element of the sorted list for squaring it?

tyw__
Автор

Why so many people are confused about sorting being nlogn. Its pretty common knowledge

tathagat
Автор

Yup this is easy, i guess the complexity is what matters here?

hodayfah
Автор

new_array size = array, array[i]^2=new_array[i], what kind of suggestion is this

CharIie
Автор

Cant you just, add the sqaures in a list then just sort that list

sameerkamani
Автор

How does it compare to merge sort and square at the end of recursion, its also O(nlogn) right?

cyberduck
Автор

Lmao why do they ask stuip questions you will never use or need to know but perhaps 1 time. Fang is a laughing stick in the Engineering feild

WirableCrown
Автор

Is this Greedy or Dynamic programming approach?

shazyzone
join shbcf.ru