Jump Game 2 (LeetCode 45) | Minimum jumps to reach end of array | Explanation with Animations

  Рет қаралды 35,127

Nikhil Lohia

Nikhil Lohia

Күн бұрын

Пікірлер: 114
@luisguarin593
@luisguarin593 Жыл бұрын
Don’t stop what your doing. You’re amazing and i learn so much from you
@vinaysagar9280
@vinaysagar9280 7 ай бұрын
great explanation, easy to understand with your graphical representation. Keep doing what you're doing.
@nilaxgajjar.work8
@nilaxgajjar.work8 5 ай бұрын
This video's explanation was fantastic! I had a hard time grasping the concept of coverage before watching it, but your clear explanation and use of animations really helped me understand. The solution you presented visually, with both drawings and animations, made it much easier to follow along and almost had me solve the problem myself by the end. Thanks for such a well-done video! 🖊
@kalpitbansal9923
@kalpitbansal9923 Жыл бұрын
Whenever I get stuck with a question, your videos always come to the rescue with clear and concise explanations. Your content has been a game-changer for my learning journey. Keep uploading more and more such tutorials.
@nikoo28
@nikoo28 Жыл бұрын
will try my best to keep bringing useful content
@prakhargarg4166
@prakhargarg4166 11 ай бұрын
+1
@prakhargarg4166
@prakhargarg4166 11 ай бұрын
You explain so clearly
@hajeeramohamad7641
@hajeeramohamad7641 6 ай бұрын
Man!!! Hands down!!! You teach reallly well. The explanation was crystal clear. Even for the recursive brute force approach, your explanation was precise. Love it. Keep doing❤❤ Till date i find recursion very confusing. Please start a recursion playlist. The way you teach is very amazing. Gets right into the head. Would love to learn recursion from you.
@thugesh123-12
@thugesh123-12 3 ай бұрын
usually i don't comment on videos but dudu u are amazing....so easily u have explained me......😇..u got a new subscriber
@nikoo28
@nikoo28 3 ай бұрын
Thank you so much 😀
@Wiseman..
@Wiseman.. 2 ай бұрын
Its my first time watching a video for you but your explanation is the best for this answer. Thank you for the quality content!
@vikashaakash5202
@vikashaakash5202 8 ай бұрын
sir i dont know how but your solution help me to understand the problem very easy ur soln for each problem is unique and easy to understand
@akashddeepchitransh4537
@akashddeepchitransh4537 4 күн бұрын
Thank you very much for this one.
@tasniatahsin8637
@tasniatahsin8637 Жыл бұрын
your videos truly are helping me understand DSA so well! Keep it up
@nikoo28
@nikoo28 Жыл бұрын
good luck 😇
@janki-bx1rn
@janki-bx1rn 4 ай бұрын
literally the best explanation ever!
@anupamakovid4568
@anupamakovid4568 10 ай бұрын
excellent explanation 👌This is my first video on your channel, really loved the explanation. Subscribing !!
@nikoo28
@nikoo28 10 ай бұрын
Thanks and welcome
@Anonymous____________A721
@Anonymous____________A721 4 ай бұрын
Literally the best one
@parthchaudhary5134
@parthchaudhary5134 Жыл бұрын
it's my first watch on your channel....u explains so good that i am subscribing you...and thank you soo much for educating us...
@nikoo28
@nikoo28 Жыл бұрын
thanks for the sub :)
@gangadharsai2705
@gangadharsai2705 10 ай бұрын
after ...coverage = max(coverage, i+arr[i]), add this if condition if(i>=coverage) return -1;// if you encounter any zero in between this edge case will help i.e., for test case: 3 2 1 0 5 code: int minJumps(vector &arr,int n) { // Write your code here. int totalJumps=0; int destination=n-1; int coverage=0; int lastJumpInd=0; if(n==1) return 0; for(int i=0;i=coverage) return -1; if(i==lastJumpInd){ lastJumpInd=coverage; totalJumps++; if(coverage>=destination) return totalJumps; } } return totalJumps; }
@dnc077
@dnc077 6 ай бұрын
I like how you explained how to solve this with the greedy approach you have taken. The way you explain with images is really great. Thanks! I am experiencing a lot of difficulty reaching the solution. More than the coding, it's finding the solution that I am really struggling with. The approach I took for this case is consider the base case and move backwards. Somehow, I find it very difficult to find my way through it. I got very confused from that stage; I considered the recursive approach but did not have a clear picture in my mind how I was going to solve it. Then again, sometimes, I come across a problem where I literally do it with much less effort. I'm not sure if it's just me but I find myself unable to find the approach to solving the problem. Once I find the approach, the coding side is easy. I don't know - that's just me. Struggling but trying! :( Thanks for sharing.
@nikoo28
@nikoo28 5 ай бұрын
I totally understand you. What you are experiencing is just a part of the coding journey. Always remember that it gets tough before it starts to get simpler. Just like you go on a hike...the start is very easy...then you begin to get tired, and it is hard to carry along. Once you cross that hurdle, the rest of the trek becomes enjoyable. :)
@nikoo28
@nikoo28 5 ай бұрын
Keep doing what you are doing...as long as you are trying to write the solutions on your own rather than just copying the code, you will succeed :)
@vaamigaming2673
@vaamigaming2673 3 ай бұрын
there are 2 cases missing 1) if first value of array is 0 , then we can't move further. 2) suppose and array 2 1 0 0 0 0 then we can't jump at the end , so we have to add case if(lastjumpindex
@vanshsharma-lg1hj
@vanshsharma-lg1hj 5 ай бұрын
better than neetcode....for this soln presentation...thanku
@mdshahidansari9126
@mdshahidansari9126 4 ай бұрын
Awesome explanation sir
@abhaypatel379
@abhaypatel379 4 ай бұрын
Excellent work 🎉
@SimpleCse2012
@SimpleCse2012 5 ай бұрын
Bhaiya in this code it would be if (lastIndex >= destination) { return totalJumps; } not Coverage>=destination
@TasneemMohammad-oj3ie
@TasneemMohammad-oj3ie 2 ай бұрын
yes thankyou
@waqaskhan2165
@waqaskhan2165 2 ай бұрын
@@TasneemMohammad-oj3ie how ??? i mean lastJumpindex and coverage arent same
@raghebadel5689
@raghebadel5689 10 ай бұрын
man you are so good, wish you all the best, all the love from Palestine
@aashanadhameja5754
@aashanadhameja5754 Жыл бұрын
To the point explanation. Thanks!
@kamalasowmya7120
@kamalasowmya7120 11 ай бұрын
great explanation Bhai! I watched the video so many times to get it. Finally was able to get the idea and solve it...Thanks for a thoughtful vid! :)
@AbhinavKumar-xo5ji
@AbhinavKumar-xo5ji 10 ай бұрын
Awsm explanation man
@shubhamroy1094
@shubhamroy1094 Жыл бұрын
badiya samjhaya
@UtkarshOjha
@UtkarshOjha Жыл бұрын
your code works perfectly on leetcode but not working on gfg, by the way great explanation
@nikoo28
@nikoo28 Жыл бұрын
you may have to tweak it a little for the different problem constraints.
@udaykirankavaturu6942
@udaykirankavaturu6942 Жыл бұрын
how to come up with such a greedy criteria, I mean what would be the thought process for a similar problem
@nikoo28
@nikoo28 11 ай бұрын
as you solve more and more problems you will be able to narrow down some patterns. When starting any new problem, you will then try to get started with those known methods first. sometimes along the way, you will tweak them and discover new methods
@riyasharma-rn2ur
@riyasharma-rn2ur 5 ай бұрын
Very good explanation sir
@nikoo28
@nikoo28 5 ай бұрын
Thanks and welcome
@Lubi879
@Lubi879 Ай бұрын
Your videos are so nice.. very helpful.. but this one is little difficult to understand
@tunebrotherdon
@tunebrotherdon Жыл бұрын
Great explanation!
@parthmodi2028
@parthmodi2028 6 ай бұрын
great explaination !! u are too good
@gayiii1911
@gayiii1911 11 күн бұрын
Thank you
@wahid4544
@wahid4544 11 ай бұрын
thanks for the helpful videos, what is the app name you use in your iPad to write and explain things?
@nikoo28
@nikoo28 10 ай бұрын
GoodNotes 6
@m-bk4um
@m-bk4um Жыл бұрын
simple and good
@itsmepratham2712
@itsmepratham2712 Жыл бұрын
Keep Going and Keep Posting
@sriyanandakuchimanchi4042
@sriyanandakuchimanchi4042 9 ай бұрын
beautiful beautiful
@raghavendravernekar4103
@raghavendravernekar4103 9 ай бұрын
nice explanation
@sahilsoni6339
@sahilsoni6339 Жыл бұрын
could you just check in the if condition where coverage>=destination at the place of coverage it will be lastIndex because if we return totalJumps without traversing till the lastIndex it will give wrong answer
@amritmohapatra8335
@amritmohapatra8335 Жыл бұрын
right
@saicharanpinninti548
@saicharanpinninti548 9 ай бұрын
yes before returning total_jumps need to increment
@michi19935
@michi19935 6 ай бұрын
Somehow, I had to replace coverage at the last if statemant with lastjumpInx because otherwise one jump was always missing: if(lastJumpIndx >= destination){ return totalJumps }
@saicharanpinninti548
@saicharanpinninti548 9 ай бұрын
thank you so much exellent explanation and i have a small doubt there is a issue with your code if(coverage>+destination){ return total_jumps; } from above part of code you are returning without incerements total_jumps for last window i think and also there is a case entire window of elements is 0 then cant go the last_index right?
@sorrybhai100
@sorrybhai100 9 ай бұрын
in leetcode there's a line which says "The test cases are generated such that you can reach nums[n - 1]". Means there will always be a way to reach the last index. So all 0 test cases won't be there. But it can be solved by putting checks for 0.
@nikoo28
@nikoo28 8 ай бұрын
absolutely correct
@mdshafiuddin1234
@mdshafiuddin1234 Жыл бұрын
Sir please make a playlist on advance recursion
@nikoo28
@nikoo28 Жыл бұрын
will do
@subee128
@subee128 10 ай бұрын
Thanks
@swarajgupta8646
@swarajgupta8646 7 ай бұрын
i have a doubt in if part that if take coverage as max at index 0 then we will reach at index 2 right which represents 1 at index 2 then if it is 1 then we can't choose 4 at index 1. Can anyone explain me that?? please help
@nikoo28
@nikoo28 7 ай бұрын
Can you please elaborate on the doubt you have. I got confused
@PrashantKumar-fk8le
@PrashantKumar-fk8le Жыл бұрын
Great man
@shibhamalik1274
@shibhamalik1274 10 ай бұрын
Does the greed criteria say that choose the element with the max value from i till i+nums[i ] ? e.g 2,1,4,1,3,1,1,2 . for i =0 , nums[0 ] = 2, We choose 4 from 1,4. After that for i becomes 2 and for nums[2 ] = 4 we have options 1,3,1,1 and we chose max which is 3 and then reach in 3 min steps till the end. ?
@nikoo28
@nikoo28 9 ай бұрын
every greed criteria will not give you the optimal solution. first we need to prove that the greed criteria we choose leads to an optimal solution. kzbin.info/www/bejne/aXmVeGaBqqqciLc
@waqaskhan2165
@waqaskhan2165 2 ай бұрын
how to decide the greedy criteria for any algirthm
@funnymoment9164
@funnymoment9164 Жыл бұрын
Thanks!
@basukinath2766
@basukinath2766 Жыл бұрын
thanks brother
@nishanthsunkara1160
@nishanthsunkara1160 Жыл бұрын
I felt understanding coverage little tricky.
@nikoo28
@nikoo28 Жыл бұрын
what part did you face a problem with?
@mikeag1371
@mikeag1371 11 ай бұрын
I have an edge case - [ 2,16,1,2,3,1,1,2 ] here when i=1 coverage will be > destination hence return totaljumps which is 1 because i!=lastjump. but coverage>=destination so 1 will be returned but correct ans is 2 jumps because from 2->16->destination I am wrong ???
@nikoo28
@nikoo28 10 ай бұрын
check the problem constraints on the actual problem page :)
@javeriyaj4101
@javeriyaj4101 3 ай бұрын
I feel like i got this n again I'm feeling like do i really got this?? What I'm going through plzz help Few days ago i started coding
@nikoo28
@nikoo28 3 ай бұрын
i totally understand this dilemma, and happens with every person who starts to code. It will get better with time as you solve more and more problems.
@ago7506
@ago7506 10 ай бұрын
sir this code is not working it gives the wrong test cases in leetcode test case:[2,3,1,1,4] Output 1 Expected 2 .........code...... class Solution { public: int jump(vector& nums) { int jumps=0; int n=nums.size(); int coverage=0; int lastJump=0; int destination=n-1; if(n==1) return 0; for(int i=0;i=destination) { return jumps; } } return jumps; } };
@nikoo28
@nikoo28 9 ай бұрын
you will need to debug the test case
@035-harshitsingh7
@035-harshitsingh7 10 ай бұрын
why we are using if(i==lastjumpindex) lastjumpindex= coverage; jumps++; can anyone explain?
@nikoo28
@nikoo28 9 ай бұрын
did you follow the explanation? please don't jump straight to the code portion.
@bigdatapartner
@bigdatapartner 8 ай бұрын
amz explanation
@vnn6568
@vnn6568 7 ай бұрын
its failing for [2,3,1,1,4].
@nikoo28
@nikoo28 7 ай бұрын
What answer are you expecting ?
@Lubi879
@Lubi879 Ай бұрын
same here -2 should be the answer but his code gives me 3 as answer
@manvendrasingh4369
@manvendrasingh4369 6 ай бұрын
There was few errors in your code but anyways nice explanation.
@nikoo28
@nikoo28 6 ай бұрын
What errors did you find?
@rajukachori9536
@rajukachori9536 5 ай бұрын
💥💥💥💥💥💥💥💥❤❤❤❤❤❤
@Udaylux
@Udaylux 5 ай бұрын
Great explanation, but, the case for when the destination cannot be reached we should return -1 is not covered
@nikoo28
@nikoo28 5 ай бұрын
if you check the problem constraints: "It's guaranteed that you can reach nums[n - 1]."
@nihal6636
@nihal6636 Жыл бұрын
code is wrong it will always give one jump less than required jumps please check
@nikoo28
@nikoo28 Жыл бұрын
did you try the code in the video description? it works perfectly on leetcode
@nihal6636
@nihal6636 Жыл бұрын
​​@@nikoo28i got the answer already myself but thank u just need to replace coverage with lastjumpindex in last condition
@nigma933
@nigma933 8 ай бұрын
@@nihal6636 thank u!
@nihal6636
@nihal6636 Жыл бұрын
bro why u post video without veryfing the code just wasting our time and your time
@Sowmyakotha-lj8te
@Sowmyakotha-lj8te Жыл бұрын
Its perfectly working fine.If condition should be placed as shown below if(i==nextInterval){ nextInterval = coverage; jumps++; if(coverage >= target ){ return jumps; } }
@nikoo28
@nikoo28 Жыл бұрын
the code works perfectly. Check the link in the description please :)
@ago7506
@ago7506 10 ай бұрын
thx buddy @@Sowmyakotha-lj8te
@piyushanand3451
@piyushanand3451 7 ай бұрын
instead of if(coverage>= destination), there should be (lastjumpIdx>=destination)
@nikoo28
@nikoo28 7 ай бұрын
Why do you think so?
@piyushanand3451
@piyushanand3451 7 ай бұрын
@@nikoo28 N = 6 arr = {1, 4, 3, 2, 6, 7} Output: 2 take this example, if you are using coverage>= destination, your output will be 1.
@nikoo2805
@nikoo2805 7 ай бұрын
@@piyushanand3451i just verified. With my solution, the output is 2 as expected. Added a test case too to confirm. Look at the video description for the file. Make sure you are implementing it correctly :)
@ridj41
@ridj41 8 ай бұрын
Not intutive at all the last one For me 1d dp was the best here
@randomeverything8304
@randomeverything8304 5 ай бұрын
The code that you provide in your videos are always WRONG!!!!!!!!!!!
@nikoo28
@nikoo28 5 ай бұрын
what do you mean? I never upload a code that is not passing all test cases on LeetCode. Did you check the link in the video description?
@arpitsaxena2906
@arpitsaxena2906 5 ай бұрын
​@@nikoo28some people are just there to cause problems 😂
@great.Indian.culture
@great.Indian.culture 3 ай бұрын
But my answer comes as 2 not 3 by ur code
@nikoo28
@nikoo28 3 ай бұрын
did you have a look at the code on my github profile?
@great.Indian.culture
@great.Indian.culture 3 ай бұрын
@@nikoo28 no I just copied this one.. u taught. Is github code different than this ??
@nikoo28
@nikoo28 3 ай бұрын
@@great.Indian.culture that has the full implementation with test cases. Check the links in video description.
@DhananjayKumar-bd2jg
@DhananjayKumar-bd2jg 8 ай бұрын
great explanation!
The Ultimate Sausage Prank! Watch Their Reactions 😂🌭 #Unexpected
00:17
La La Life Shorts
Рет қаралды 8 МЛН
When u fight over the armrest
00:41
Adam W
Рет қаралды 31 МЛН
ТЮРЕМЩИК В БОКСЕ! #shorts
00:58
HARD_MMA
Рет қаралды 2,6 МЛН
L5. Jump Game - II | Greedy Algorithm Playlist
16:45
take U forward
Рет қаралды 67 М.
#Leetcode 45 Jump Game 2 || Code + Explanation + Example Walkthrough
12:42
I Solved 100 LeetCode Problems
13:11
Green Code
Рет қаралды 245 М.
Jump Game II - Greedy - Leetcode 45 - Python
11:58
NeetCode
Рет қаралды 208 М.
LeetCode was HARD until I Learned these 15 Patterns
13:00
Ashish Pratap Singh
Рет қаралды 577 М.