LeetCode 55. Jump Game (Algorithm Explained)

แชร์
ฝัง
  • เผยแพร่เมื่อ 2 ม.ค. 2020
  • 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

  • @nimanizky
    @nimanizky 4 ปีที่แล้ว +15

    That algorithm explanation section helps so much

  • @ravishekhawat5489
    @ravishekhawat5489 4 ปีที่แล้ว +18

    That was some clean explanation Nick. I was aware of only the O(n2) solution. Keep it up.

  • @azfarzaidi513
    @azfarzaidi513 3 ปีที่แล้ว +10

    This is simply beautiful! You've really taught me something on how to think about a solution approach! Thank you Nick!

  • @yashsheth3033
    @yashsheth3033 4 ปีที่แล้ว +4

    Absolutely loved the explanation and how you broke it down into smaller sub problems! Superb stuff!

  • @vivekgr3001
    @vivekgr3001 4 ปีที่แล้ว +1

    love the way you explain the code using dry runs

  • @jamesgeng7815
    @jamesgeng7815 4 ปีที่แล้ว +2

    This is the best and easy-understanding solution I can tell. Thank you dude, excellent

  • @seshafermi5776
    @seshafermi5776 4 ปีที่แล้ว +1

    Thank a bunch Nick, it was so much clearer after your explaining.

  • @bulianxile
    @bulianxile 4 ปีที่แล้ว +7

    Love your video and the way you are talking dude!

  • @BadriBlitz
    @BadriBlitz 3 ปีที่แล้ว +1

    Well the approach is so good and explained really well.Thanks Nick.

  • @palak2708
    @palak2708 4 ปีที่แล้ว +1

    Probably your best explanation! Great video.

  • @Harjotse
    @Harjotse 2 ปีที่แล้ว +1

    i was strugling with the sol from last 3 days but you made it clear in just 10 min kudos for your efforts

  • @sitaramakella8922
    @sitaramakella8922 3 ปีที่แล้ว

    best explanation I have seen for this problem !! thanks Nick !

  • @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.

  • @xxsanyxx1
    @xxsanyxx1 2 ปีที่แล้ว

    Great explanation and beautiful code! Thanks Nick!

  • @sarthakpatidar1099
    @sarthakpatidar1099 3 ปีที่แล้ว

    The explanation was awesome and you made it look easy. Thanks

  • @Fapados123
    @Fapados123 3 ปีที่แล้ว +2

    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 8 หลายเดือนก่อน

      cuz recursive approach TS is in exponential form , which is uh.. really bad.. you can see the question's constraints.@@cindrasenareddy1929

  • @urvashichaudhuri9516
    @urvashichaudhuri9516 4 ปีที่แล้ว +1

    Thanks for the explanation Nick. Nice approach. In case you have solved Leetcode 45 too (Jump Game II), could you share your solution?

  • @NickWhite
    @NickWhite  4 ปีที่แล้ว +25

    how am i still covering the code...

    • @user-sj3fp2xq2m
      @user-sj3fp2xq2m 4 ปีที่แล้ว

      Rookie mistake! Jk, no worries, still helpful.

  • @kirtipalve1772
    @kirtipalve1772 2 ปีที่แล้ว

    Best explanation, clean and concise. thanks!

  • @sumanmallipeddi5950
    @sumanmallipeddi5950 2 ปีที่แล้ว +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 ปีที่แล้ว

      Last good index means smallest index from which path to last index is possible

  • @t3techtilltoday861
    @t3techtilltoday861 3 ปีที่แล้ว

    you are amazing bro, short and on-point. Perfect video :-)

  • @wigcrafter
    @wigcrafter 4 ปีที่แล้ว

    really love your video, how is ur interview going so far?

  • @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

  • @ricardongh72
    @ricardongh72 2 ปีที่แล้ว

    Great strategy bro ! Sometimes those simple solutions can be hard to think of

  • @mrhelloimstupid
    @mrhelloimstupid 4 ปีที่แล้ว +2

    Hey, do you also have a video for jump game 2?

  • @CricketThomas
    @CricketThomas 4 ปีที่แล้ว +1

    good explanation! you should make a video about how you may not need leetcode for a dev job

  • @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

  • @johnnywilson3071
    @johnnywilson3071 3 ปีที่แล้ว +1

    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.

  • @fadi.casual3796
    @fadi.casual3796 4 ปีที่แล้ว

    Can you explain the minimum number of jumps (aka jump game ii) required to reach the end. @Nick

  • @rajeshkartha147
    @rajeshkartha147 4 ปีที่แล้ว

    Wow.. Thanks a lot. Very clear explanation.

  • @hhjdkdnchidnd
    @hhjdkdnchidnd 2 ปีที่แล้ว

    super easy to understand after watching your video!!

  • @satyamgupta6030
    @satyamgupta6030 ปีที่แล้ว

    another great solution, sweet and simple.

  • @satang500
    @satang500 3 ปีที่แล้ว +3

    thanks for the video, but your small rectangle bottom-left corner covers some of the code part/writing when you're explaining.

  • @harshthakkar7503
    @harshthakkar7503 4 ปีที่แล้ว

    Nicely explained bro!!!

  • @BronToLearnBornToTeach
    @BronToLearnBornToTeach 3 ปีที่แล้ว

    wow... the explaination, now this problem look really easy

  • @nileshpatil3710
    @nileshpatil3710 2 ปีที่แล้ว

    clean, neat and easy to understand.

  • @cocoandcairo
    @cocoandcairo 4 ปีที่แล้ว

    Really good Explanation

  • @saumya1singh
    @saumya1singh 3 ปีที่แล้ว +1

    awesome Nick

  • @gu3566
    @gu3566 ปีที่แล้ว

    Love your explanation!

  • @ashishbarai1425
    @ashishbarai1425 4 ปีที่แล้ว

    Awesome 👍
    Best in you tube one can find

  • @duongvuhai1222
    @duongvuhai1222 5 หลายเดือนก่อน

    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

  • @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

  • @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.

  • @dishagupta7446
    @dishagupta7446 2 ปีที่แล้ว

    amazing explaination!!

  • @shubhangishinde5544
    @shubhangishinde5544 3 ปีที่แล้ว

    Will you make one video on Jump Game 2 ?

  • @thegreatsilence1081
    @thegreatsilence1081 3 ปีที่แล้ว

    Hi Nick ..I did not get why you have comapre i+nums[i] >= lastGoodIndexPosition....why not just to compare nums[i]

  • @user-us7rg4cd6p
    @user-us7rg4cd6p หลายเดือนก่อน

    This is genius! Thanks a ton

  • @milenitrivedi7561
    @milenitrivedi7561 2 ปีที่แล้ว

    nice explanation !

  • @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

  • @stith_pragya
    @stith_pragya 8 หลายเดือนก่อน

    Thank You So Much for this wonderful video...................🙏🙏🙏🙏🙏🙏

  • @abhishekrajgeek
    @abhishekrajgeek 4 ปีที่แล้ว

    Amazing! Thannks!!

  • @myvinbarboza3038
    @myvinbarboza3038 4 ปีที่แล้ว

    awesome Thank you

  • @coordinator3039
    @coordinator3039 5 หลายเดือนก่อน

    Really having trouble with all the interview problems. I need an explanation of how I can understand these algorithms

  • @tejasnakhate
    @tejasnakhate 4 ปีที่แล้ว

    Please do Jump game II and Jump game III

  • @sayoojvalsan4879
    @sayoojvalsan4879 3 ปีที่แล้ว

    why i + nums[i] >=. What is ">" doing here. Sorry could not understand that part

  • @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! :/

  • @anonymousreviewer3816
    @anonymousreviewer3816 3 ปีที่แล้ว

    Thank You!!

  • @mohammedsadiq5729
    @mohammedsadiq5729 4 ปีที่แล้ว

    Nick
    Spiral Matrix lll
    🙏

  • @etherioussanjudraganeel3163
    @etherioussanjudraganeel3163 2 ปีที่แล้ว

    Thnx Jonathan

  • @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.

  • @willturner3440
    @willturner3440 3 ปีที่แล้ว

    How to know minimum number of steps

  • @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 ปีที่แล้ว +1

      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 ปีที่แล้ว +1

      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 ปีที่แล้ว +2

      ​@@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 ปีที่แล้ว +2

      @@NickWhite which coursera course did you took

    • @tweissin
      @tweissin 3 ปีที่แล้ว

      Yes what was the Coursera course?

  • @suzy1107
    @suzy1107 2 ปีที่แล้ว

    it's == at the return statement, but overall great explanation!

  • @abhilashgoyal2234
    @abhilashgoyal2234 4 ปีที่แล้ว +1

    You can start the loop from "nums.length - 2" also. That will also be logically correct

    • @Hav0c1000
      @Hav0c1000 4 ปีที่แล้ว +1

      not if nums[-2] is 0

    • @vaidehiyadav5507
      @vaidehiyadav5507 2 ปีที่แล้ว

      what about the corner case then .where there is single entity in the array.

  • @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.

  • @roycrxtw
    @roycrxtw 2 ปีที่แล้ว

    Brilliant.

  • @catmium7974
    @catmium7974 ปีที่แล้ว

    Danke!

  • @kriswright5112
    @kriswright5112 3 ปีที่แล้ว

    your algorithm was O(N), but your rambling goodbye was O(N^2)

  • @Hav0c1000
    @Hav0c1000 4 ปีที่แล้ว +2

    I hate this question... It looks like Graph Search, It looks like back tracking... and then the answer is just reverse linear sweep...

  • @prathyushagade3501
    @prathyushagade3501 3 ปีที่แล้ว

    you're too good at explaining it!

  • @rupaldesai7098
    @rupaldesai7098 4 ปีที่แล้ว

    I din get how nums[i]+i is handling the logic

    • @NickWhite
      @NickWhite  4 ปีที่แล้ว +5

      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 ปีที่แล้ว +2

      @@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! :-)

  • @marq_8976
    @marq_8976 3 หลายเดือนก่อน

    I still don't understand how it works for the FALSE example.

  • @madanmohanpachouly6135
    @madanmohanpachouly6135 2 ปีที่แล้ว

    nice

  • @shivamshukla9277
    @shivamshukla9277 2 ปีที่แล้ว

    Eminem - Im the fastest rapper alive
    Nick - Hey nick white here fndfsojdbfldmf.........

  • @100bands
    @100bands 4 ปีที่แล้ว +1

    Never felt more stupid...damn it

  • @vishalagrawal246
    @vishalagrawal246 4 ปีที่แล้ว +1

    please dry run this testcase [2,0,0] with your algo...
    thanks :)

    • @crapid5252
      @crapid5252 4 ปีที่แล้ว +2

      returns True

  • @upol92
    @upol92 2 ปีที่แล้ว

    This will not work for many cases including [2,0,0]

  • @Sanyat100
    @Sanyat100 3 ปีที่แล้ว

    Comon bro. Use JavaScript ! I

  • @LordLobov
    @LordLobov 3 ปีที่แล้ว

    This problem is not intuitive at all :((

  • @krishnavar7219
    @krishnavar7219 ปีที่แล้ว

    srikrishna

  • @koownmyo
    @koownmyo 2 ปีที่แล้ว

    the hate I have for this problem is unreal

  • @mannana8550
    @mannana8550 2 ปีที่แล้ว

    Please dont cover text with your video. Thanks.

  • @aronblanche
    @aronblanche 4 หลายเดือนก่อน

    return nums[nums.length-2]!=0;
    why not this one liner?