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!
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.
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
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.
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
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].
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 !!😃😃
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 =
[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].
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.
Neetcode is at another level, hats off
agreed
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!
Man you are killing it!!!!!!!!!!!! You are one of my favorite instructor!
You do, what you do best
I'm prepping for my final Google round and your videos have been essential in my study. Thanks a ton!
Best of luck bro🔥
You got this!
final round meaning host? or HC?
@@cc-to2jn onsite
@@mightyshenanigans2607 I hope you get the job, you got this
Hey - can you make a video for Wiggle Sort 2?
As always, this was super easy to understand. Thanks!
Would love a video around your interview details from Google. What rounds were there, what complexity, what was expected, etc.
This can be found easily if you search on google btw
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.
interesting that if the requirement is for string < > rather than =, this approach completely breaks down
It didn't work for input array [5,5,5,5,4,4,4,4]
@@udayptp we must handle the case of a==b also
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!
Lol. Google pays well but not enough to afford Leetcode. You're hilarious.
Man of explanation 🔥
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
Thanks bro for ur videos.
This explanation was spot on. So grateful
"Google pays me pretty well but not enough to afford leetcode premium of course" xD lmao cracked me up
This man was born to explain.
Your explanations are awesome! Would you be able to do a video on 1405. Longest Happy String?
There are so many types of sorts it's crazy. Bogo sort is my favorite tho xd
I believe there is a bogobogo sort too.
rip our boy posted this on valentines day. we need a neetgirl for our neetcode
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.
Hey @NeetCode good works. I like your works. Could you please make a video on wiggle sort 2? thank You
Do you mind also covering wiggle sort II?
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
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?
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].
Thanks for the video! Can you please solve Wiggle Sort 2, Leetcode. 324
Interviews are to understand how you think!
Your explanations are awesome 🔥.
Thanks for this.
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 !!😃😃
Wait really, which one is it?
@@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)
You're awesome!!!
[5,5,5,4,4,4,4] will make the solution invalid?
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 =
[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].
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.
Wow google cant pay 150 dollars surprised XD. Just kidding. its a penny for google software engineers or may be less than penny :)
Not enough to afford Leetcode premium 😂😂
If the array contains duplicate elts then?
What about if input array is [5,5,5,5,4,4,4,4] .
The array is wiggle sort itself, no reorder needed.
Yeah Lintcode also wants me to log in using my WeChat account. No thanks China 👍
Thanks God Meta and Google don't collect their users data. China bad US good raaaaaaaaaaahhhhhhh 🦅🦅🦅🦅🦅🦅
@@andrewknyazkov6877lollll
Google should give employees free leetcode premium as perk~
"google pays me well but not well enough to afford leetcode premium". Come on man!
who's here because they tryna solve Wiggle Sort 2 first lol
Lintcodee user
Looking forward to watching wiggle sort Ⅱ : )