LeetCode 55. Jump Game (Algorithm Explained)

  Рет қаралды 76,826

Nick White

Nick White

4 жыл бұрын

The Best Place To Learn Anything Coding Related - bit.ly/3MFZLIZ
Join my free exclusive community built to empower programmers! - www.skool.com/software-develo...
Preparing For Your Coding Interviews? Use These Resources
--------------------
(My Course) Data Structures & Algorithms for Coding Interviews - thedailybyte.dev/courses/nick
AlgoCademy - algocademy.com/?referral=nick...
Daily Coding Interview Questions - bit.ly/3xw1Sqz
10% Off Of The Best Web Hosting! - hostinger.com/nickwhite
Follow My Twitter - / nicholaswwhite
Follow My Instagram - / nickwwhite
Other Social Media
----------------------------------------------
Discord - / discord
Twitch - / nickwhitettv
TikTok - / nickwhitetiktok
LinkedIn - / nicholas-w-white
Show Support
------------------------------------------------------------------------------
Patreon - / nick_white
PayPal - paypal.me/nickwwhite?locale.x...
Become A Member - / @nickwhite
#coding #programming #softwareengineering

Пікірлер: 108
@azfarzaidi513
@azfarzaidi513 3 жыл бұрын
This is simply beautiful! You've really taught me something on how to think about a solution approach! Thank you Nick!
@ravishekhawat5489
@ravishekhawat5489 4 жыл бұрын
That was some clean explanation Nick. I was aware of only the O(n2) solution. Keep it up.
@yashsheth3033
@yashsheth3033 4 жыл бұрын
Absolutely loved the explanation and how you broke it down into smaller sub problems! Superb stuff!
@nimanizky
@nimanizky 4 жыл бұрын
That algorithm explanation section helps so much
@Harjotse
@Harjotse 2 жыл бұрын
i was strugling with the sol from last 3 days but you made it clear in just 10 min kudos for your efforts
@satyamgupta6030
@satyamgupta6030 Жыл бұрын
nick my brother you don't know how much ur videos help me in building approach and solving a problem. Your approach are always better than others please keep on making such videos.
@aditimangs
@aditimangs 3 жыл бұрын
@nick, Do you have a solution to Leetcode 45 with similar approach, where you start iterating from the right end of Index
@vivekgr3001
@vivekgr3001 4 жыл бұрын
love the way you explain the code using dry runs
@jamesgeng7815
@jamesgeng7815 4 жыл бұрын
This is the best and easy-understanding solution I can tell. Thank you dude, excellent
@mrhelloimstupid
@mrhelloimstupid 4 жыл бұрын
Hey, do you also have a video for jump game 2?
@seshafermi5776
@seshafermi5776 4 жыл бұрын
Thank a bunch Nick, it was so much clearer after your explaining.
@NickWhite
@NickWhite 4 жыл бұрын
how am i still covering the code...
@user-sj3fp2xq2m
@user-sj3fp2xq2m 4 жыл бұрын
Rookie mistake! Jk, no worries, still helpful.
@sitaramakella8922
@sitaramakella8922 3 жыл бұрын
best explanation I have seen for this problem !! thanks Nick !
@thegreatsilence1081
@thegreatsilence1081 3 жыл бұрын
Hi Nick ..I did not get why you have comapre i+nums[i] >= lastGoodIndexPosition....why not just to compare nums[i]
@palak2708
@palak2708 4 жыл бұрын
Probably your best explanation! Great video.
@bulianxile
@bulianxile 4 жыл бұрын
Love your video and the way you are talking dude!
@xxsanyxx1
@xxsanyxx1 2 жыл бұрын
Great explanation and beautiful code! Thanks Nick!
@fadi.casual3796
@fadi.casual3796 4 жыл бұрын
Can you explain the minimum number of jumps (aka jump game ii) required to reach the end. @Nick
@Fapados123
@Fapados123 3 жыл бұрын
Now that's a simple and efficient solution, combined with good explanation. I didn't even think of going backwards, just tried to brute-force it recursively.
@cindrasenareddy1929
@cindrasenareddy1929 Жыл бұрын
then why is leetcode is not accepting the solution . its giving TLE
@69_kalesh
@69_kalesh 9 ай бұрын
cuz recursive approach TS is in exponential form , which is uh.. really bad.. you can see the question's constraints.@@cindrasenareddy1929
@BadriBlitz
@BadriBlitz 3 жыл бұрын
Well the approach is so good and explained really well.Thanks Nick.
@urvashichaudhuri9516
@urvashichaudhuri9516 4 жыл бұрын
Thanks for the explanation Nick. Nice approach. In case you have solved Leetcode 45 too (Jump Game II), could you share your solution?
@DurgeshYadav-bc5nm
@DurgeshYadav-bc5nm 2 жыл бұрын
This is actually quite neat. It only does whatever the questions asks.. nothing more. We don't really need to explore all possibilities when we only need to return whether or not it's possible to reach the last index. Cool solution this
@rosonerri-faithful
@rosonerri-faithful 3 жыл бұрын
Nick since the return type asked is boolean,keep the return values as true and false,other than i and 0. good explaination. understood it
@satang500
@satang500 4 жыл бұрын
thanks for the video, but your small rectangle bottom-left corner covers some of the code part/writing when you're explaining.
@sarthakpatidar1099
@sarthakpatidar1099 3 жыл бұрын
The explanation was awesome and you made it look easy. Thanks
@satyamgupta6030
@satyamgupta6030 Жыл бұрын
another great solution, sweet and simple.
@wigcrafter
@wigcrafter 4 жыл бұрын
really love your video, how is ur interview going so far?
@kirtipalve1772
@kirtipalve1772 3 жыл бұрын
Best explanation, clean and concise. thanks!
@t3techtilltoday861
@t3techtilltoday861 3 жыл бұрын
you are amazing bro, short and on-point. Perfect video :-)
@ricardongh72
@ricardongh72 2 жыл бұрын
Great strategy bro ! Sometimes those simple solutions can be hard to think of
@hhjdkdnchidnd
@hhjdkdnchidnd 2 жыл бұрын
super easy to understand after watching your video!!
@sumanmallipeddi5950
@sumanmallipeddi5950 2 жыл бұрын
Nice Explanation. But technically I don't think we have to start from last Index as we are moving from behind and we dont care whats the value in the last index as we have reached there. (On line 4, we can start from lastGoodIndexPosition-1 (which is num.length-2))
@arishsheikh3000
@arishsheikh3000 2 жыл бұрын
Last good index means smallest index from which path to last index is possible
@sayoojvalsan4879
@sayoojvalsan4879 3 жыл бұрын
why i + nums[i] >=. What is ">" doing here. Sorry could not understand that part
@CricketThomas
@CricketThomas 4 жыл бұрын
good explanation! you should make a video about how you may not need leetcode for a dev job
@gu3566
@gu3566 Жыл бұрын
Love your explanation!
@BronToLearnBornToTeach
@BronToLearnBornToTeach 3 жыл бұрын
wow... the explaination, now this problem look really easy
@coordinator3039
@coordinator3039 6 ай бұрын
Really having trouble with all the interview problems. I need an explanation of how I can understand these algorithms
@dishagupta7446
@dishagupta7446 2 жыл бұрын
amazing explaination!!
@duongvuhai1222
@duongvuhai1222 6 ай бұрын
the last index's value does not matter so we can skip it by doing nums.length -2 instead of nums.length -1 in the loop
@shubhangishinde5544
@shubhangishinde5544 3 жыл бұрын
Will you make one video on Jump Game 2 ?
@nileshpatil3710
@nileshpatil3710 2 жыл бұрын
clean, neat and easy to understand.
@johnnywilson3071
@johnnywilson3071 3 жыл бұрын
This method seems a lot easier than trying to do it via DFS/Backtracking. You could also start the loop from "last_good_index_position -1" or nums.size()-2 as long as LGIP is initialized as nums.size()-1. It would mean one less loop required which probably makes minimal difference in terms of speed.
@kellenstuart4698
@kellenstuart4698 2 жыл бұрын
Yeah that's what I was thinking
@rajeshkartha147
@rajeshkartha147 4 жыл бұрын
Wow.. Thanks a lot. Very clear explanation.
@user-us7rg4cd6p
@user-us7rg4cd6p 2 ай бұрын
This is genius! Thanks a ton
@SaifUlIslam-di5xv
@SaifUlIslam-di5xv Жыл бұрын
I had a gut feeling there was some approach I could solve this starting at the last index, but I was unsure of that.
@stith_pragya
@stith_pragya 9 ай бұрын
Thank You So Much for this wonderful video...................🙏🙏🙏🙏🙏🙏
@josephwu9455
@josephwu9455 3 жыл бұрын
the 'i + nums[i] >= lastGoodIndexPosition' part is hard to grasp initially until using a test case '2 0 0', now it clicks. thanks
@harshthakkar7503
@harshthakkar7503 4 жыл бұрын
Nicely explained bro!!!
@willturner3440
@willturner3440 3 жыл бұрын
How to know minimum number of steps
@milenitrivedi7561
@milenitrivedi7561 2 жыл бұрын
nice explanation !
@cocoandcairo
@cocoandcairo 4 жыл бұрын
Really good Explanation
@ashishbarai1425
@ashishbarai1425 4 жыл бұрын
Awesome 👍 Best in you tube one can find
@saumya1singh
@saumya1singh 3 жыл бұрын
awesome Nick
@himanshusingh694
@himanshusingh694 3 жыл бұрын
I have solved 70 easy questions and 5 medium questions on leetcode.. still can't think of these solutions.. born with a freezed mind! :/
@abhishekrajgeek
@abhishekrajgeek 4 жыл бұрын
Amazing! Thannks!!
@etherioussanjudraganeel3163
@etherioussanjudraganeel3163 2 жыл бұрын
Thnx Jonathan
@alokesh985
@alokesh985 2 жыл бұрын
Amazing stuff. This is why I love solving problems. What I thought was a pretty straightforward backtracking question turned out to be a reverse linear traversal
@anonymousreviewer3816
@anonymousreviewer3816 3 жыл бұрын
Thank You!!
@myvinbarboza3038
@myvinbarboza3038 4 жыл бұрын
awesome Thank you
@tejasnakhate
@tejasnakhate 4 жыл бұрын
Please do Jump game II and Jump game III
@hamicartoon
@hamicartoon 4 жыл бұрын
I think this will work only for 1st index, will not work if i want jump from other index. Ex a[]={2, 0, 1, 1, 4}, the code will true. where as it should fail when will start from index 1
@pauljustin9583
@pauljustin9583 3 жыл бұрын
The question is you have to start from 1st index.
@suzy1107
@suzy1107 2 жыл бұрын
it's == at the return statement, but overall great explanation!
@carpettunnel8837
@carpettunnel8837 4 жыл бұрын
Did you come up with your solution on the fly during the video or did you solve the problem ahead of time?
@NickWhite
@NickWhite 4 жыл бұрын
I’ve solved this problem in a Coursera course I took before and it said I submitted a solution 10 months ago as well so I was pretty familiar with the problem
@carpettunnel8837
@carpettunnel8837 4 жыл бұрын
Nick White Felt slightly less dumb after reading your comment as my initial thinking while watching was to start from the beginning of the array...feeling dumb again after finding my previous comment was directly addressed at the end of the video. 🤣 Maybe try putting the video of yourself on screen right as it decreases the probability of it covering a line of code.
@benh2908
@benh2908 4 жыл бұрын
​@@NickWhite Hey, by any chance, do you remember the name of that Coursera course? And/or do you have any other courses you recommend? Thanks!
@sachinshrestha2538
@sachinshrestha2538 4 жыл бұрын
@@NickWhite which coursera course did you took
@tweissin
@tweissin 3 жыл бұрын
Yes what was the Coursera course?
@marq_8976
@marq_8976 4 ай бұрын
I still don't understand how it works for the FALSE example.
@Hav0c1000
@Hav0c1000 4 жыл бұрын
I hate this question... It looks like Graph Search, It looks like back tracking... and then the answer is just reverse linear sweep...
@mohammedsadiq5729
@mohammedsadiq5729 4 жыл бұрын
Nick Spiral Matrix lll 🙏
@catmium7974
@catmium7974 Жыл бұрын
Danke!
@roycrxtw
@roycrxtw 3 жыл бұрын
Brilliant.
@sarscov9854
@sarscov9854 3 жыл бұрын
Damn. I thought the question was asking that you can ONLY jump the number of steps at nums[i]. But it actually means you can jump nums[i] or less. The solution for my former knocks out almost all test cases, but it is the wrong answer. Apparently, you have to do backtracking.
@kriswright5112
@kriswright5112 3 жыл бұрын
your algorithm was O(N), but your rambling goodbye was O(N^2)
@rupaldesai7098
@rupaldesai7098 4 жыл бұрын
I din get how nums[i]+i is handling the logic
@NickWhite
@NickWhite 4 жыл бұрын
nums[i] is how many indices you can jump forward and i is the current index so it basically just tells you the farthest index you can jump from your current position
@rupaldesai7098
@rupaldesai7098 4 жыл бұрын
@@NickWhite Thanks! Appreciate the brief explanation. Understood now!
@0anant0
@0anant0 4 жыл бұрын
@@rupaldesai7098 Sometimes it helps to use descriptive local variables int curMaxJump = nums[i]; if (i + curMaxJump >= lastGoodIndex) Sometimes, you can give descriptive names to the 'magic numbers' in code: final int EMPTY = 0, WALL = 1; final int X = 0, Y = 1; if (cell[X] == dest[X] && cell[Y] == dest[Y]) return true; ... if (board[newRow][newCol] == WALL) continue; This will help when you are reviewing your own code at a later date! :-)
@madanmohanpachouly6135
@madanmohanpachouly6135 2 жыл бұрын
nice
@shivamshukla9277
@shivamshukla9277 3 жыл бұрын
Eminem - Im the fastest rapper alive Nick - Hey nick white here fndfsojdbfldmf.........
@upol92
@upol92 2 жыл бұрын
This will not work for many cases including [2,0,0]
@DurgeshYadav-bc5nm
@DurgeshYadav-bc5nm 2 жыл бұрын
It works
@prathyushagade3501
@prathyushagade3501 4 жыл бұрын
you're too good at explaining it!
@abhilashgoyal2234
@abhilashgoyal2234 4 жыл бұрын
You can start the loop from "nums.length - 2" also. That will also be logically correct
@Hav0c1000
@Hav0c1000 4 жыл бұрын
not if nums[-2] is 0
@vaidehiyadav5507
@vaidehiyadav5507 2 жыл бұрын
what about the corner case then .where there is single entity in the array.
@100bands
@100bands 4 жыл бұрын
Never felt more stupid...damn it
@vishalagrawal246
@vishalagrawal246 4 жыл бұрын
please dry run this testcase [2,0,0] with your algo... thanks :)
@crapid5252
@crapid5252 4 жыл бұрын
returns True
@Sanyat100
@Sanyat100 3 жыл бұрын
Comon bro. Use JavaScript ! I
@LordLobov
@LordLobov 3 жыл бұрын
This problem is not intuitive at all :((
@koownmyo
@koownmyo 2 жыл бұрын
the hate I have for this problem is unreal
@krishnavar7219
@krishnavar7219 Жыл бұрын
srikrishna
@krishnavar7219
@krishnavar7219 Жыл бұрын
6:42
@mannana8550
@mannana8550 2 жыл бұрын
Please dont cover text with your video. Thanks.
@aronblanche
@aronblanche 5 ай бұрын
return nums[nums.length-2]!=0; why not this one liner?
Jump Game - Greedy - Leetcode 55
16:28
NeetCode
Рет қаралды 220 М.
УГАДАЙ ГДЕ ПРАВИЛЬНЫЙ ЦВЕТ?😱
00:14
МЯТНАЯ ФАНТА
Рет қаралды 2,9 МЛН
DEFINITELY NOT HAPPENING ON MY WATCH! 😒
00:12
Laro Benz
Рет қаралды 56 МЛН
DAD LEFT HIS OLD SOCKS ON THE COUCH…😱😂
00:24
JULI_PROETO
Рет қаралды 14 МЛН
Beautiful gymnastics 😍☺️
00:15
Lexa_Merin
Рет қаралды 14 МЛН
I Got Rejected (again)
9:43
Nick White
Рет қаралды 203 М.
LeetCode 36. Valid Sudoku (Algorithm Explained)
11:33
Nick White
Рет қаралды 97 М.
Jump Game - Leetcode 55 - Dynamic Programming (Python)
8:42
Greg Hogg
Рет қаралды 1,2 М.
I Solved 1583 Leetcode Questions  Here's What I Learned
20:37
ThePrimeTime
Рет қаралды 581 М.
LeetCode 56. Merge Intervals (Algorithm Explained)
12:57
Nick White
Рет қаралды 89 М.
I gave 127 interviews. Top 5 Algorithms they asked me.
8:36
Sahil & Sarra
Рет қаралды 623 М.
LeetCode Spiral Matrix Solution Explained - Java
11:07
Nick White
Рет қаралды 48 М.
❌ Don't Run Behind 500 LEETCODE Problems ❌ Focus on QPCD
8:31
Jump game | Leetcode #55 | Valley peak approach
12:28
Techdose
Рет қаралды 184 М.
Самые крутые школьные гаджеты
0:49
САМЫЙ ДОРОГОЙ ЧЕХОЛ! В стиле Mac Pro
0:35
Romancev768
Рет қаралды 100 М.
$1 vs $100,000 Slow Motion Camera!
0:44
Hafu Go
Рет қаралды 25 МЛН
НЕ ПОКУПАЙ СМАРТФОН, ПОКА НЕ УЗНАЕШЬ ЭТО! Не ошибись с выбором…
15:23
ОБСЛУЖИЛИ САМЫЙ ГРЯЗНЫЙ ПК
1:00
VA-PC
Рет қаралды 2,1 МЛН