This is the first video among all, which could clearly explain to me the logic of the greedy approach used here and get convinced with the intuition. 1. Though i could not find any resources on the internet which could help me understand the process - How can I come up with such intuition. 2. But at least, this video was really helpful to get convinced for the algorithm. and then I was able to write a correct code my self. Many Thanks.
@c9bd4155 жыл бұрын
Thank you, couldn't understand those descriptions on leetcode..
@NideeshTerapalli5 жыл бұрын
Haha you're welcome
@bakguff2 жыл бұрын
Dude, great explanation. I was really confused by other explanations of this problem but this helped out alot!
@ptitm26673 жыл бұрын
great explanation! very clear and easy to understand! I'm Chinese so I usually watch videos explained in Chinese bc it's easy to understand, but I found yours is much clearer! Thank you
@BackToBackSWE5 жыл бұрын
Do you have a contact? I want to talk to you
@sparshsharma60682 жыл бұрын
Halfway through the video and I got an AC on leetcode just by understanding the way you explained the intuition! Thanks a lot
@ramanahlawat3982 жыл бұрын
thanks man!! appreciate the help nice explanation too!!
@harshtyagi7002 жыл бұрын
You nailed the explaination part. Thanks!!
@arthamsreenivas88584 жыл бұрын
Thank you brother, leetcode solution is very hard to understand, keep going on!
@NideeshTerapalli4 жыл бұрын
Thanks Artham
@thomashirtz3 жыл бұрын
Seriously, nice job I saw a video of you some time ago, it's cool to see your evolution, and see you making them cleaner and better every time 👌
@NideeshTerapalli3 жыл бұрын
Thanks Thomas, I'm always getting a tiny bit better every day
@nopecharon2 жыл бұрын
What a beast explanation. You earned a new sub
@learnninspire79842 жыл бұрын
great explanation bro!
@fahadabdullah6872 жыл бұрын
Greatly explained. It's todays daily challenge on leetcode. 19 aug 2022.
@nagalakshmi13854 жыл бұрын
great video as always! The best way to explain the intuition behind solving the problem, you always do best among all. Thanks a lot !
@saumya1singh4 жыл бұрын
Superb Nideesh!
@manasdeora46012 жыл бұрын
Loved the explanation. Could not think of this approach.
@AYJ959 Жыл бұрын
Thanks a lot dude , you explained it very well!
@diaoyuanhuzhenhuiqi Жыл бұрын
really the best explaination i seen
@kewtomrao2 жыл бұрын
Thats an amazing explanation!
@anderswb3 жыл бұрын
This solution is tricky to get your head around at first but this is a great and concise explanation.
@manojborugadda92122 жыл бұрын
Excellent explanation Nideesh anna😀😀🙌
@prabhatkumar-eg2rg3 жыл бұрын
Good stuff Nideesh. Keep cracking on.
@NideeshTerapalli3 жыл бұрын
Thanks Prabhat
@shenth274 жыл бұрын
Excellent explanation with always sticking to the point.
@vishweshpujari25842 жыл бұрын
Best explanation for this problem. Thanks!
@prempeacefulchannel2 жыл бұрын
You explained it very clearly. Thanks a lot bro!
@rakshith35474 жыл бұрын
by far the best explanation for this problem.. keep up the good work bro
@bhargavamarpina82944 жыл бұрын
Nice Explanation.
@swapanshridhar14 жыл бұрын
Perfect. Very helpful explanation. Thanks!
@ChanChan-pg4wu2 жыл бұрын
Nice Work!
@quirkyquester2 жыл бұрын
this is a fire video brother! Thank you! brilliant!
@koushikkumar51562 жыл бұрын
Nice explanation
@rajarshisarkar54884 жыл бұрын
Very clear explanation! Thanks.
@sachinwathore37734 жыл бұрын
Thanks a lot Nideesh for an awesome explanation. I found it very helpful !
@nishantdhamija28802 жыл бұрын
that was really good
@tanmaypahuja2064 жыл бұрын
Amazing explanation! Thanks a lot!
@akhilchakravarthy4 жыл бұрын
Good job dude
@toekneema3 жыл бұрын
thank you! great walkthrough!
@mashab91293 жыл бұрын
brilliant solution. thanks for sharing.
@thegt4 жыл бұрын
Very nice explanation! Great job man!
@nikhil.pandey2 жыл бұрын
smooth
@kollivenkatamadhukar50594 жыл бұрын
Can you please explain your taught process how you arrived at the solution, I mean how did you get to know you have to use an hypothetical map....
@Cloud-5772 жыл бұрын
thank you :) you are great at explaining
@rajatbudania61814 жыл бұрын
Plz upload more videos, these are really helpful mate!
@pukhrajsoni40202 жыл бұрын
Excellent explanation
@labi95002 жыл бұрын
thanks!
@navidr28114 жыл бұрын
great job explaining it man!
@shantanukshire794 жыл бұрын
Super solution !
@chuyi86644 жыл бұрын
Thank you! it is really helpful
@saicharan86754 жыл бұрын
Super cool thanks for sharing
@_ADITIKAJALE3 жыл бұрын
best explanation ! thanks :))
@guolongli66674 жыл бұрын
NICE IDEA AND WONDERFUL EXPLANATION! you help me solve the problem :>
@iriswei30184 жыл бұрын
very helpful!
@NideeshTerapalli4 жыл бұрын
You're welcome
@yashbansal15204 жыл бұрын
Great explanation
@DSUNDAR_2 ай бұрын
In short, 3 cases : case1: can join existing group-> check anybody wants the current number by looking hypothetical map. case2: eligible to create a group case3: not eligible to create group as well cannot join any group. return false
@RagazzoKZ5 жыл бұрын
I think it would be interesting to consider edge cases. What if you have two sequences expecting the same number? In this case, you should push the number into the shorter sequence. I used a priority queue for that. But it's not the best solution. const map = new Map() // storing priority queues of sequences, key is the expecting number (i.e. next number in sequence) for (let num of nums) { let prevPq = map.get(num - 1) let subseq if (!prevPq) { subseq = new Subseq(num) } else { subseq = prevPq.pop() subseq.addLast(num) if (prevPq.isEmpty()) { map.delete(num - 1) } } let nextPq = map.get(num) if (!nextPq) { nextPq = new PriorityQueue() } nextPq.push(subseq) map.set(num, nextPq) } for (let [key, pq] of map) { for (let subseq of pq._heap) { if (!subseq.isValid()) { return false } } } return true my Subseq class: class Subseq { constructor(last) { this.last = last this.len = 1 } addLast(last) { this.last = last this.len++ } getLast() { return this.last } getLen() { return this.len } isValid() { return this.len > 2 } }
@NideeshTerapalli5 жыл бұрын
Interesting, thanks for sharing this. I actually did not explore a solution with a Priority Queue, appreciate going over it.
@sumitkumar-ps9rl4 жыл бұрын
HI Nideesh, It was really helpful. I used multiset from c++ in place of a map. Thank You.
@NideeshTerapalli4 жыл бұрын
Happy to help
@kaichenghu38264 жыл бұрын
Thanks for your explanation
@NideeshTerapalli4 жыл бұрын
You're welcome
@TrenBlack5 жыл бұрын
Have you ever done Candy Crush? It is leetcode 723... (You might need leetcode premium to access it)
@NideeshTerapalli5 жыл бұрын
Hey Tren, I won't be able to make videos on leetcode premium questions since they are private on their website. Sorry about that!
@rajatbudania61814 жыл бұрын
Very Nice Explanation! )-
@NideeshTerapalli Жыл бұрын
Hey there! Just wanted to let you know that some of the links in this comment are affiliate links, which means that if you make a purchase through them, I may earn a small commission. Don't worry though, it doesn't cost you anything extra and it helps support this channel so I can continue to make more videos for you. Thank you so much for your support, and as always, all opinions are my own! Start getting great at system design: bytebytego.com?fpr=nideesh (affiliate link) Handpicked Algorithms and Data Structures for Interview To Save Time: interviewpen.com/?via=nideesh (affiliate link) Fast track to becoming a knowledgeable SWE www.educative.io/unlimited?aff=K1z6 (affiliate link)
@RagazzoKZ5 жыл бұрын
Wow, new videos!
@NideeshTerapalli5 жыл бұрын
Yup, sorry for the delay. I remember you requested this one, hope it helps!
@gurpreetchawla20663 жыл бұрын
Hypothetical Map shows - ( key , demand of a number ) . Incase someone's confused what hypothetical map do.
@sarthakchoudhary8114 жыл бұрын
very nice.
@ajr1791ze4 жыл бұрын
amazing.
@sabbispeak4 жыл бұрын
nice expaalanaation mate
@jaesungj4 жыл бұрын
While the explanation was really good do you have any good resource on the steps toward how we eventually came up with this algorithm?
@NideeshTerapalli4 жыл бұрын
Hi JJ, sorry I don't. I gave credit to the original post in the video description. Looks like "greedy" algos don't have the same templates as other questions like say backtracking. Will share it if I find though
@algorithmimplementer4154 жыл бұрын
Could you group this kind of questions that are a bit tricky and relevant to crack big tech company interview? Thanks!
@NideeshTerapalli4 жыл бұрын
Good idea
@chamcham38064 жыл бұрын
Why are we trying to append to the hypothetical map first (preferring it over starting a new sequence from the current element) ?
@NideeshTerapalli4 жыл бұрын
Which line in the code are you referring to? Or you could tell me which part of the video you had in mind. But if you are asking in general why does an element try to append itself to an existing sequence instead of starting a new one, the reasons are as follows: 1) This is a greedy approach 2) If a number can join a subsequence that is already generated then it will do so because the algorithm's job is to identify (true/false) whether or not we can generate valid subsequences. If a number is always trying to start a new subsequence then it might not have all the elements in the array/frequency map to create a valid subsequence. That's why a number will prefer to join a subsequence if it can and in doing so create a new "hypothetical" spot for the next integer which may come from anywhere in the array. Feel free to ask more questions
@chamcham38064 жыл бұрын
@@NideeshTerapalli Thanks for your quick reply. Got it cleared.
@HOW--22 жыл бұрын
What does hypothetical map mean bro ?
@akshatjain77424 жыл бұрын
Why do we need to keep numbers with value 0 in the Hmap? Those are the numbers that can no longer be accepted, right?
@NideeshTerapalli4 жыл бұрын
Hmap is actually just hypothetical k-v storage. We might encounter a number later in the array which belong there. Feel free to ask more clarifying questions if i didn't explain clearly