Rearrange Array Elements by Sign - Leetcode 2149 - Python
🚀 neetcode.io/ - A better way to prepare for Coding Interviews
🧑💼 LinkedIn: / navdeep-singh-3aaa14161
🐦 Twitter: / neetcode1
⭐ BLIND-75 PLAYLIST: • Two Sum - Leetcode 1 -...
Problem Link: leetcode.com/problems/rearran...
0:00 - Read the problem
0:24 - Drawing Explanation 1
4:06 - Coding Explanation 1
6:13 - Drawing Explanation 2
8:50 - Coding Explanation 2
leetcode 2149
#neetcode #leetcode #python
Пікірлер: 19
damn i spent a lot of time thinking of in-place solution and come here, is there a inplace algorithm?
@luminica_
5 ай бұрын
Of course you can do it in place but it won't be O(n) TC. Don't swap but actually move the element.
@aaroldaaroldson708
5 ай бұрын
same
What I did instead of the pointer is that reverse the positive and negative array then pop each element to a res array as an input. (Like a stack)
@avidfan3407
5 ай бұрын
Simple but smart
you can use a two pointer technique to find the next positive and negative number in the array. Then add the positive and negative number to the result array before moving the pointers again. No extra memory
Or also we can use hashtable [0] * len(nums) and we should fill by appropriate values
With list comprehension we can make two lists and then use a zip function 😊
as we dont consider output space we can say this as constant space solution
hi, man i am getting good at coding now but the problem is my resume is not getting shortlisted at any good companies since I'm not from a tier 1 college, would be great if u made a video or post about it. What good will all the skills do when i don't have the chance to perform
@Aditya_qwertyu
5 ай бұрын
same difficulty
whats good bro
Hi Neetcode any chance u could do 3009 pls?
I solved this on the first attempt, however runtime: beats 5%, memory: beats 90%. Hm, there might be a trick here using a bit more memory :D
Neet solution
just do for num in nums :) no need for k i hate to be that guy but i fail to see why this is a medium problem.. many people critique the wording of the question as it suggests this should be done in place..whereas in fact its not the case as the editorial also creates a new array.. what is your thoughts on the difficulty label and the constant war in the comment sections... oh this should be easy ... bla bla ... and then someone comes and freaks out why discourage ppl if they cannot solve the problem and its labelled easy... i think it is important to have accurate labels as it is supposed to give an accurate measure of my knowledge... i think it is really misleading if medium problems are in fact easy cos it can create a false sense of knowledge... but also re labeling like straight forward dynamic programming questions from hard to medium is also neccessary as it show that the industry has evolved to a point where solving these problems is a must now and dont fall into the expert knowledge category cheers
@pastori2672
5 ай бұрын
theres no difference its just personal prefrence
@leeroymlg4692
5 ай бұрын
it's not that deep bro. take it with a grain of salt
what are these comments