Wiggle Sort - Leetcode 280 - Python

  Рет қаралды 25,054

NeetCode

NeetCode

Күн бұрын

Пікірлер: 62
@unmeshkadam4876
@unmeshkadam4876 3 жыл бұрын
Neetcode is at another level, hats off
@metarus208
@metarus208 2 жыл бұрын
agreed
@devonfulcher
@devonfulcher 3 жыл бұрын
Hey @Neetcode, I really enjoy your content. I watch it everyday to prepare for my interviews. I have a suggestion. Could you post content of you going into a question blind? I would really like to see your thought process when you don't know the answer. Thanks! Keep up the excellent content!
@mightyshenanigans2607
@mightyshenanigans2607 3 жыл бұрын
I'm prepping for my final Google round and your videos have been essential in my study. Thanks a ton!
@jackwalker2947
@jackwalker2947 3 жыл бұрын
Best of luck bro🔥
@vour6654
@vour6654 3 жыл бұрын
You got this!
@cc-to2jn
@cc-to2jn 3 жыл бұрын
final round meaning host? or HC?
@mightyshenanigans2607
@mightyshenanigans2607 3 жыл бұрын
@@cc-to2jn onsite
@squeeps33
@squeeps33 3 жыл бұрын
@@mightyshenanigans2607 I hope you get the job, you got this
@ratikdubey4375
@ratikdubey4375 2 жыл бұрын
Hey - can you make a video for Wiggle Sort 2? As always, this was super easy to understand. Thanks!
@mishkathossain2984
@mishkathossain2984 3 жыл бұрын
Man you are killing it!!!!!!!!!!!! You are one of my favorite instructor! You do, what you do best
@ngneerin
@ngneerin 3 жыл бұрын
Would love a video around your interview details from Google. What rounds were there, what complexity, what was expected, etc.
@chinesemimi
@chinesemimi 3 жыл бұрын
This can be found easily if you search on google btw
@AlexN2022
@AlexN2022 2 жыл бұрын
interesting that if the requirement is for string < > rather than =, this approach completely breaks down
@udayptp
@udayptp 2 жыл бұрын
It didn't work for input array [5,5,5,5,4,4,4,4]
@haitamelgharras
@haitamelgharras 8 ай бұрын
@@udayptp we must handle the case of a==b also
@midkay
@midkay Жыл бұрын
Just a heads up, the problem solved in this video differs slightly from Leetcode's version of the problem. Leetcode's version requires values to be strictly greater or less than ("equal to" is not allowed), so the logic presented here, while solid for the problem shown in the video, breaks down when applied to Leetcode's version of the problem. One example of a test case it fails is [5,5,5,4,4,4,4] because simply swapping successive pairs of elements can't move one of the four values all the way back to the start of the array where it is needed. A solution for the Leetcode version of the problem requires different logic entirely.
@tiberiusvetus9113
@tiberiusvetus9113 3 жыл бұрын
Lol. Google pays well but not enough to afford Leetcode. You're hilarious.
@yonatangafri4670
@yonatangafri4670 5 ай бұрын
Thanks!!! Our teacher gave this question but with given median, perhaps it for make it easier. but now i see your solution and it is so simple!
@sibysuriyan9980
@sibysuriyan9980 2 жыл бұрын
rip our boy posted this on valentines day. we need a neetgirl for our neetcode
@poptart007-b2r
@poptart007-b2r 3 жыл бұрын
"Google pays me pretty well but not enough to afford leetcode premium of course" xD lmao cracked me up
@jackwalker2947
@jackwalker2947 3 жыл бұрын
Man of explanation 🔥
@esorty1913
@esorty1913 Жыл бұрын
You could have made the if statement smaller. if (not i%2 ^ nums[i] < nums[i-1]). That way you xor over the both cases and only if both are true or false it will ttigger. It is slightly different though, as the second case would also be executed with
@gasgeek434
@gasgeek434 3 жыл бұрын
This man was born to explain.
@anshdholakia1060
@anshdholakia1060 3 жыл бұрын
There are so many types of sorts it's crazy. Bogo sort is my favorite tho xd
@omkarbhale442
@omkarbhale442 Жыл бұрын
I believe there is a bogobogo sort too.
@Kshitij-fw7bh
@Kshitij-fw7bh 3 жыл бұрын
Thanks bro for ur videos.
@oluwatimilehinoyewo8010
@oluwatimilehinoyewo8010 2 жыл бұрын
This explanation was spot on. So grateful
@johncenakiwi
@johncenakiwi 3 жыл бұрын
Not enough to afford Leetcode premium 😂😂
@hammadmaya7109
@hammadmaya7109 3 жыл бұрын
Your explanations are awesome! Would you be able to do a video on 1405. Longest Happy String?
@alexwatts1375
@alexwatts1375 3 жыл бұрын
Interviews are to understand how you think!
@blancosj
@blancosj 3 жыл бұрын
I am following you since a year and I will have interview with google soon. Would you consider your videos to have google interview level?
@mohammedsamsuddin5126
@mohammedsamsuddin5126 2 жыл бұрын
Hey @NeetCode good works. I like your works. Could you please make a video on wiggle sort 2? thank You
@tchsu1140
@tchsu1140 2 жыл бұрын
Do you mind also covering wiggle sort II?
@vidhishah9154
@vidhishah9154 3 жыл бұрын
Hi Neetcode, Thank you for the remarkable explanation. Can you please make a video on split BST ? That is premium leetcode problem and there are no explanation videos available for that problem. Thanks again for the videos and making difficult problems enjoyable.
@harry8
@harry8 11 ай бұрын
This solution, while it seems simple, doesn't work on Leetcode for the test case [5,5,5,4,4,4,4]. This is because it is only swapping locally, and so fails to deal with cases where there are multiple repeated elements. Here, there will be a number of 4's at the end, instead of the array being [4,5,4,5,4,5,4].
@Jayavarshini_Jayakumaran
@Jayavarshini_Jayakumaran 2 жыл бұрын
Thanks for the video! Can you please solve Wiggle Sort 2, Leetcode. 324
@anandkumar.3307
@anandkumar.3307 3 жыл бұрын
Haha i thought this is some different problem but actually I have solved it on leetcode itself but with some different name which is not a premium problem though !!😃😃
@NeetCode
@NeetCode 3 жыл бұрын
Wait really, which one is it?
@ayoubalem865
@ayoubalem865 3 жыл бұрын
@@NeetCode the second version of it. Num on leetcode: 324 . instead of (gt or eq) or (ls or eq) you have (gt strictly) or (ls strictly)
@haitamelgharras
@haitamelgharras 8 ай бұрын
Thanks NeetCode, I tried to solve the wiggle sort 2 with the same approach but it doesnt work, even when trying to handle the equal case, I think about finding the first diff value and swap one of the repeated values with this diff value but it doesnt work
@weifang9143
@weifang9143 3 жыл бұрын
[5,5,5,4,4,4,4] will make the solution invalid?
@alexanderhurst1998
@alexanderhurst1998 2 жыл бұрын
Why would that solution not work? If we skip to index 3 (the first four) because we don't have to swap any of the fives, and even if we did it wouldn't matter 3 is odd which means we want it to be larger than or equal to the elements around it We find that it is less than index two so we swap those We now have [5,5,4,5,4,4,4] We move on to index 4 which is even so we want it to be less than or equal to neighbors It is so we do nothing and all the rest are 4 so we do nothing Now if we write out the list with greater than equal, less than equal signs we get 5 = 4 = 4 =4 Which is true Of course the solution [4,5,4,5,4,5,4] is more pleasing but it isn't any more correct unless you specify that you are looking strictly < and > rather than =
@badalwanjari4964
@badalwanjari4964 3 жыл бұрын
You're awesome!!!
@mynk_rjpt
@mynk_rjpt 3 жыл бұрын
Your explanations are awesome 🔥.
@krishnachaitanya1265
@krishnachaitanya1265 3 жыл бұрын
Wow google cant pay 150 dollars surprised XD. Just kidding. its a penny for google software engineers or may be less than penny :)
@metarus208
@metarus208 2 жыл бұрын
Thanks for this.
@yutianzhang6058
@yutianzhang6058 Жыл бұрын
Google should give employees free leetcode premium as perk~
@Axl124124
@Axl124124 Жыл бұрын
"google pays me well but not well enough to afford leetcode premium". Come on man!
@dipeshjoshi8064
@dipeshjoshi8064 2 жыл бұрын
[5,5,5,4,4,4,4] this input is not Working. Since you are running loop from index 1 to n, first element is excluded. I have used different algo, which might be helpful to other. 1. run quick selection algorithm for index = n/2. (Make sure to run it inplace, since it is mentioned in question.) 2. after running quick select your median would be at proper place. So now you can assign left pointer at 0th index and right pointer on (n/2)+1 the index. 3. Now run loop over array and alternatively (i.e. index%2==1) you can swap a[left] with a[right].
@midkay
@midkay Жыл бұрын
The problem isn't that the loop runs from index 1 to n and excludes the first element - it's that this entire algorithm doesn't work properly on the Leetcode version of this problem, because Leetcode's version of the problem requires values to be strictly greater or less than ("equal to" is not allowed). So simply swapping the "5"s at indexes 0 and 1, or 1 and 2, would never lead to a correct result - we need to pull over one of the "4"s later in the array. Leetcode's version of the problem requires different logic entirely.
@AkashSharma-ij4sn
@AkashSharma-ij4sn Жыл бұрын
If the array contains duplicate elts then?
@theantonlulz
@theantonlulz 2 жыл бұрын
Yeah Lintcode also wants me to log in using my WeChat account. No thanks China 👍
@andrewknyazkov6877
@andrewknyazkov6877 Жыл бұрын
Thanks God Meta and Google don't collect their users data. China bad US good raaaaaaaaaaahhhhhhh 🦅🦅🦅🦅🦅🦅
@midkay
@midkay Жыл бұрын
​@@andrewknyazkov6877lollll
@udayptp
@udayptp 2 жыл бұрын
What about if input array is [5,5,5,5,4,4,4,4] .
@SweetDarkViolet
@SweetDarkViolet 2 жыл бұрын
The array is wiggle sort itself, no reorder needed.
@shooby117
@shooby117 Жыл бұрын
who's here because they tryna solve Wiggle Sort 2 first lol
@MANRAJSINGHCO
@MANRAJSINGHCO Жыл бұрын
Lintcodee user
@tetsu0xyz
@tetsu0xyz 2 жыл бұрын
Looking forward to watching wiggle sort Ⅱ : )
Remove K Digits - Leetcode 402 - Python
14:36
NeetCode
Рет қаралды 66 М.
Версия без цензуры в 🛒 МИРАКЛЯНДИЯ
00:47
Провальная Акция в Seven Eleven
00:51
Тимур Сидельников
Рет қаралды 2,6 МЛН
Squid game
00:17
Giuseppe Barbuto
Рет қаралды 37 МЛН
How Strong is Glass? 💪
00:25
Brianna
Рет қаралды 29 МЛН
What if all the world's biggest problems have the same solution?
24:52
Learn Quick Sort in 13 minutes ⚡
13:49
Bro Code
Рет қаралды 449 М.
4Sum - Leetcode 18 - Python
15:28
NeetCode
Рет қаралды 88 М.
I gave 127 interviews. Top 5 Algorithms they asked me.
8:36
Sahil & Sarra
Рет қаралды 694 М.
I Spent 100 Hours Inside The Pyramids!
21:43
MrBeast
Рет қаралды 76 МЛН
Dynamic Programming isn't too hard. You just don't know what it is.
22:31
DecodingIntuition
Рет қаралды 249 М.
C can do this too and it's faster than Python
2:09:48
Tsoding Daily
Рет қаралды 23 М.
But what are Hamming codes? The origin of error correction
20:05
3Blue1Brown
Рет қаралды 2,5 МЛН
Jump Game II - Greedy - Leetcode 45 - Python
11:58
NeetCode
Рет қаралды 224 М.
Версия без цензуры в 🛒 МИРАКЛЯНДИЯ
00:47