Noob vs Pro Developer on Squares of a Sorted Array

preview_player
Показать описание
Noob vs Pro Developer on Squares of a Sorted Array

#programming #coding
Рекомендации по теме
Комментарии
Автор

Join 65k+ Developers Studying for Tech Interviews for FREE at Algomap.io!

GregHogg
Автор

First coder wins because he saved enough time to play a game of catch with his son

YohoKnows
Автор

First method is significantly easier to understand, and unless that causes slowness wherein a two pointer approach works best, then I fail to see any reason to optimize it further given it reduces readability

michaelkovalsky
Автор

That 96% in first solution tells a lot about python leetcoders😂

temirbek
Автор

We can also have two lists, one of the negative numbers and the other of positive numbers. Then, we square each number, and reverse the list of the negative numbers. Finally, we can merge the two lists. The entire process would also take O(n).

(Correct me if im wrong, i dont know much)

ilovee
Автор

I would say the noob coder wins this one 95% in memory and about 33% in runtime, while the Sleepy guy only got 97% in runtime only 2 percent higher that noobs memory and 16% in memory vs 33% in runtime. The noob wins overall

LeetStack
Автор

premature optimization is the root of hell

SeRoShadow
Автор

I’ll keep in mind the second approach in the next 20 years of my career since I somehow managed just fine using the first approach in the first 20.

dotnetside
Автор

Okay, dumb question, but if the array is already sorted, why do we need to do anything? The exponential function is increasing (i.e., if a>b, then a^2>b^2), if I remember the math terminology correctly. Couldn't we just do a mapping type of thing that simply takes each value in the array, squares it, and puts it back in the array at that location? Should be O(n) there too cause we only have to go through once and it is already sorted as demonstrated by mathematical principle. Why do we need a pointer?

trumpetbob
Автор

The forehead slap really resonated with me

willklep
Автор

The first method used less memory and beat a higher percentage of submissions.

fadious_padious
Автор

You're using python. If you want performance, just use C.

fortnitegamer-yphd
Автор

maybe it's a hot take on my part, but I think unless you work in a MAANG, or a company working with big data, the first solution will always suit your needs without performance issues.

kleberferreira
Автор

You wrote more code that was less maintainable for minimal gain. Junior programmer moment

Bruh-spbj
Автор

Considering the modern CPUs are super fast l, even those in phones, there is no need to worry about performance if your array doesn't have a ton of elements.
I hate people who overcomplicate stuff just for the sake of showing off how nerds they are

MrDragos
Автор

If it's already sorted in ascending order, why not just loop through it and replace the indexes. So basically solution #1 but you don't resort you return

yeetskeet
Автор

If the array is already sorted why sort it again after finding the squares

LightninKng
Автор

First method was easier, had less lines, and was easier to read

TGIQ-ZW
Автор

Maybe I don't understand the problem, but you don't have sort the resultant array as the input array is already sorted. You can just do `i*i for i in input_ary`

SkamanSamTyler
Автор

why is a second sorting needed when the input was already sorted? When the input numbers are in sorted order, than taking their squares in O(n) time would be sorted too, because the higher a number the higher it's square

florianvo
visit shbcf.ru