Jump Game (LeetCode 55) | Full solution with animations and visuals | Greedy Algorithms

Sdílet
Vložit
  • čas přidán 23. 07. 2024
  • Actual problem on LeetCode: leetcode.com/problems/jump-ga...
    Chapters:
    00:00 - Intro
    00:45 - Problem statement and description
    04:13 - Brute Force/Recursion/Dynamic Programming
    07:57 - A simple test case
    09:17 - Greedy Efficient Approach
    15:26 - Dry-run of Code
    17:38 - Final Thoughts
    📚 Links to topics I talk about in the video:
    Greedy Algorithmic Paradigm: • Greedy Algorithms with...
    Problems on Arrays: • Arrays
    Other Medium Difficulty Problems: • Medium Problems
    📘 A text based explanation is available at: studyalgorithms.com
    Code on Github: github.com/nikoo28/java-solut...
    Test-cases on Github: github.com/nikoo28/java-solut...
    📖 Reference Books:
    Starting Learn to Code: amzn.to/36pU0JO
    Favorite book to understand algorithms: amzn.to/39w3YLS
    Favorite book for data structures: amzn.to/3oAVBTk
    Get started for interview preparation: amzn.to/39ysbkJ
    🔗 To see more videos like this, you can show your support on: www.buymeacoffee.com/studyalg...
    🎥 My Recording Gear:
    Recording Light: amzn.to/3pAqh8O
    Microphone: amzn.to/2MCX7qU
    Recording Camera: amzn.to/3alg9Ky
    Tablet to sketch and draw: amzn.to/3pM6Bi4
    Surface Pen: amzn.to/3pv6tTs
    Laptop to edit videos: amzn.to/2LYpMqn
    💻 Get Social 💻
    Follow on Facebook at: / studyalgos
    Subscribe to RSS feeds: studyalgorithms.com/feed/
    Join fan mail: eepurl.com/g9Dadv
    #leetcode #programming #interview

Komentáře • 86

  • @namanpande7644
    @namanpande7644 Před 6 měsíci +5

    This is actually a very good explanation. I was able to understand because of the dry-run of the code. Thanks a lot.

  • @meghan6819
    @meghan6819 Před 5 měsíci +4

    Your solutions and explanations are great!! thank you

  • @arupgope2676
    @arupgope2676 Před 2 měsíci

    your explanation is great. I have tried many dsa channels to follow. Then I find this channel. It is so great and underrated.

  • @nagendravelpuri444
    @nagendravelpuri444 Před 9 měsíci

    For this problem i seen many videos, but this one was crystal clear and i never forget.
    Very Good Job Sir.

  • @shwetakumari-ms2xg
    @shwetakumari-ms2xg Před 10 měsíci +2

    watching your video for the first time, really liked your explanation. Would watch more of your videos :) thanks!

    • @nikoo28
      @nikoo28  Před 9 měsíci

      Glad you like them!

  • @nexonsensei3793
    @nexonsensei3793 Před 4 měsíci

    I watched so many videos n i could not understand the problem , after watching your video i finally understood it🥺🔥 the visualisation helped alot to understand

  • @nandinideshpande1467
    @nandinideshpande1467 Před 5 dny

    your explanation was very simple. made me understand the problem.

  • @surenderreddy6294
    @surenderreddy6294 Před měsícem

    fantastic brilliant,explanation sir,you deserve a lot

  • @akashvijayasarathy6234
    @akashvijayasarathy6234 Před 4 měsíci

    this is a gem of a video.

  • @amitshukla2268
    @amitshukla2268 Před 7 měsíci

    Very nice explanation, thanks, keep it up :)

  • @ankitchaurasiya529
    @ankitchaurasiya529 Před 2 měsíci

    Just Wow...
    I understand after watching first time this video.

  • @suyashrahatekar4964
    @suyashrahatekar4964 Před 10 měsíci +2

    underrated channel

  • @arjitgautam365
    @arjitgautam365 Před 5 měsíci +1

    really helpful. Thanks a lot!

  • @rambhaktuchihaobito7987
    @rambhaktuchihaobito7987 Před 3 měsíci +1

    thank u sir ... for such a great explanation❣❣

  • @gauravjain969
    @gauravjain969 Před 9 měsíci

    Awesome explanation 🔥

  • @catsadogga1651
    @catsadogga1651 Před měsícem

    your explanation is super

  • @kunalkheeva
    @kunalkheeva Před 9 měsíci

    Dry run really helped! thanks a tonne!

  • @arslanmuhammad4190
    @arslanmuhammad4190 Před 11 měsíci +1

    Hi Sir, You are gem. I am learning from you a lot. Thanks, Sir for this Help.

    • @nikoo28
      @nikoo28  Před 11 měsíci

      It's my pleasure

  • @user-zo6gw8mz7g
    @user-zo6gw8mz7g Před 8 měsíci

    Thank you for your work!

  • @ABDULKALAM-ig2dd
    @ABDULKALAM-ig2dd Před 11 měsíci +2

    Sir I am big fan of your leetcode playlist, Regularly folllowing it ,Please continue doing more videos on leetcode ,Waiting for more Leetcode problems ❤

    • @nikoo28
      @nikoo28  Před 11 měsíci +1

      i am adding more and more problems when I get time. Trying to cover important problems first :)

    • @ABDULKALAM-ig2dd
      @ABDULKALAM-ig2dd Před 11 měsíci

      @@nikoo28 🤍

  • @tejas5331
    @tejas5331 Před 4 měsíci

    i like how you explain with Animation

  • @workHolic-ne6eo
    @workHolic-ne6eo Před 7 měsíci

    thats the video i was searching exactly

  • @user-zo6gw8mz7g
    @user-zo6gw8mz7g Před 8 měsíci

    Thank you, you helped me so much!

    • @nikoo28
      @nikoo28  Před 8 měsíci

      You're very welcome!

  • @jk-sm6qr
    @jk-sm6qr Před 3 měsíci

    Nice explaination, Thank you

    • @nikoo28
      @nikoo28  Před 3 měsíci +1

      You are welcome

  • @Ayushkumar-co9mc
    @Ayushkumar-co9mc Před 4 měsíci

    Best explanation ever

  • @Karan9.9
    @Karan9.9 Před 6 měsíci

    very nice and clear explanation thanks !!!

    • @nikoo28
      @nikoo28  Před 6 měsíci

      Glad it was helpful!

  • @satyam_28
    @satyam_28 Před 5 měsíci

    Cool explanation bhai...and an advice...keep content concise and outro subtle

    • @nikoo28
      @nikoo28  Před 5 měsíci

      i try my best, but everyone has their own learning pace. for quick learners, i have chapter markers for faster navigation 😄

  • @abhishekomprakash4074
    @abhishekomprakash4074 Před 7 měsíci

    Super useful.💯

  • @Paradox82827
    @Paradox82827 Před 4 měsíci

    Very good explaination!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!

  • @saisree04
    @saisree04 Před 2 měsíci

    Thanks a ton

  • @LetsGo-ro1iq
    @LetsGo-ro1iq Před 3 měsíci +1

    Great Video

  • @tanishkaagarwal6750
    @tanishkaagarwal6750 Před 11 měsíci

    sir your explaination is awesome... keep uploading more videos.

    • @nikoo28
      @nikoo28  Před 10 měsíci

      thanks for your feedback, keep watching :)

  • @paridhishrivastava9133
    @paridhishrivastava9133 Před 10 měsíci

    thankyou so much sir its too good

  • @srikanthchebrolu1091
    @srikanthchebrolu1091 Před 11 měsíci +4

    I'm fan of ur way of teaching
    I learnt trees because of u
    Hope you start dp playlist like trees
    please ♥️😇

  • @murugesh1915
    @murugesh1915 Před měsícem

    Nice content

  • @subee128
    @subee128 Před 6 měsíci +1

    Thanks

  • @taslimarahmanprema8643
    @taslimarahmanprema8643 Před 7 měsíci +1

    Best one

  • @MadpolygonDEV
    @MadpolygonDEV Před 11 měsíci +2

    Incredible presentation as always. Would love to have you do a problem solving mindset tips and tricks.

    • @nikoo28
      @nikoo28  Před 10 měsíci

      that is a really great idea, I will add it to my pipeline of upcoming videos

  • @nehakanki1606
    @nehakanki1606 Před 5 měsíci

    Got itt👍

  • @TraySoek
    @TraySoek Před 11 měsíci +1

    brilliant

  • @hamdasalam4373
    @hamdasalam4373 Před 4 dny

    could you please create a video for leetcode 2483?

  • @usmanrangrez-cd7zj
    @usmanrangrez-cd7zj Před 10 měsíci +1

    class Solution {
    public:
    bool canJump(vector& nums) {
    int n=nums.size();
    int maxJump=0;
    for(int i=0;imaxJump)
    return false;
    maxJump = max(maxJump,i+nums[i]);
    if(i>=n-1)
    return true;
    }
    return false;
    }
    };

  • @jamesk6884
    @jamesk6884 Před 5 měsíci +1

    amazing explanation, love the video.
    this is my algorithm before watching ur video, it only passed 120/170 test cases when i tried to submit it. So i just wanted to know if my approach to this question is definitely incorrect.
    class Solution {
    public boolean canJump(int[] nums) {
    int size = nums.length-1;
    int sum = 0;
    for (int i=0; i < nums.length-1; i++){
    sum += nums[i];
    }
    if (sum-(nums.length-2)>= size){
    return true;
    } else if (nums[0]>= nums.length-1){
    return true;
    } else{
    return false;
    }
    }
    }
    again, thx for the video

  • @raghavachekuri7270
    @raghavachekuri7270 Před 10 měsíci

    outstanding explination plz try to do playlist for DP ur explination is 🥳

    • @nikoo28
      @nikoo28  Před 9 měsíci

      I have a playlist on DP. Constantly adding more and more problems to it: czcams.com/play/PLFdAYMIVJQHPXtFM_9mpwwQtIdzP6kxHS.html

  • @shubhamkumar-hx1fb
    @shubhamkumar-hx1fb Před 6 měsíci

    i really hate kind of videos which doesnt tells the intuition why we are doing so.....there are many videos avl for this pblm and many of them are just doing the dry run of the code without telling the intuition behind their though process....
    But i am really thanks to you sir that you focused more on the intuition behind the code and have not just done the dry run 😌😌

    • @nikoo28
      @nikoo28  Před 5 měsíci

      glad you liked it

  • @Shhhh-ni5jw
    @Shhhh-ni5jw Před 3 měsíci

    With this approach, we never stop on the 0’s right? We are checking if somehow we are able to bypass

  • @filmbuzz9419
    @filmbuzz9419 Před 9 měsíci

    Take a value and show it by dry run so we understand a bit more Thanks

  • @mahadishakkhor123
    @mahadishakkhor123 Před 4 měsíci

    i understand from u

  • @razataggarwal7365
    @razataggarwal7365 Před 7 měsíci +1

    Why we are calling optimal solution as greedy algorithm ?
    My perspective :
    If I see it, we have optimized our Iterative DP (Tabulation) by going to every index from last to first and asking if i can reach target or not.

  • @abhinavprasad2828
    @abhinavprasad2828 Před 7 měsíci

    Okay so, I don't usually comment but yeah this video was great.

    • @nikoo28
      @nikoo28  Před 7 měsíci

      Thank you so much

  • @bipinsingh1490
    @bipinsingh1490 Před 10 měsíci

    Bhai quality explaintaion h apka great baki CZcams channel toh bs code padh dete h intuition toh batate v nhi h

    • @nikoo28
      @nikoo28  Před 9 měsíci

      i like to focus on the problem solving, rather than the language. Languages will come and go. 😅, logic will stay

  • @user-ro3eh8ry9b
    @user-ro3eh8ry9b Před 4 měsíci

    Its O(N**2) ?? Can anyone explain in case of DP

    • @nikoo28
      @nikoo28  Před 4 měsíci

      why do you want a solution with a poor time complexity?

  • @gurudassulebhavikar
    @gurudassulebhavikar Před 7 měsíci +1

    You could have used your Jump Game 2 solution here. Both problems are almost same.

  • @amitshukla2268
    @amitshukla2268 Před 7 měsíci +1

    Please add your chair also in your Recording Gear? Did you buy it from amazon ?

    • @nikoo28
      @nikoo28  Před 7 měsíci

      Links in the description :)

    • @amitshukla2268
      @amitshukla2268 Před 7 měsíci

      @@nikoo28 i didn't find it.

    • @nikoo28
      @nikoo28  Před 5 měsíci

      Chair is from Autonomous.

  • @Mr.NothingSpecial
    @Mr.NothingSpecial Před 4 měsíci

    You're basically looking for the last reachable index at each iteration. That is not a greedy approach. Can you explain what do you mean by greedy approach?

    • @nikoo28
      @nikoo28  Před 4 měsíci

      My greed is that I want to reach the last pointer from where I am standing

  • @subhashreesahoo5760
    @subhashreesahoo5760 Před 2 měsíci

    Hi.. Thanks for the vide, your explanation is really good and helpful.
    But I do have doubt here and a request while explaining , pls consider the code also .
    I feel like the explanation and the dry run code somewhere I am unable to understabnd(may be I need more practice but still..)
    Example-> while explaining you said to go back step from 1 , that is 0, you cant reach the destination => agree
    but in dry run code-> idx+nums[idx] , how are you bringing these terms, like how did you think its should be in this way , its like idx=7,nums[7]=0 and you are adding both 7+0=7, so i am not getting how your idea is to add idx+nums[idex].

    • @nikoo28
      @nikoo28  Před 2 měsíci

      If you have understood the explanation, try to write the code on your own. That is the only way you will learn. If everything else fails, only then refer to someone else’s code.

    • @subhashreesahoo5760
      @subhashreesahoo5760 Před 2 měsíci

      @@nikoo28 ok sure, Thank you, I will take your advice and implement the same.

  • @DigvijayKirti
    @DigvijayKirti Před 5 měsíci

    What if the second last element is zero?
    Let's dry run the provided array [3, 2, 1, 0, 4] through the given canJump method:
    Dry run:
    Initial State: lastElement = 4 (index of the last element).
    Iteration 1 (i = 3):
    i + nums[i] = 3 + 0 >= 4, which is less than lastElement. No update.
    Iteration 2 (i = 2):
    i + nums[i] = 2 + 1 >= 4, which is less than lastElement. No update
    Iteration 3 (i = 1):
    i + nums[i] = 1 + 2 >= 4, which is less than lastElement. No update
    Iteration 4 (i = 0):
    i + nums[i] = 0 + 3 >= 4, which is less than lastElement. No update
    Return: lastElement == 0, which is true.
    So, for the array [3, 2, 1, 0, 4], the canJump method returns true, indicating that it is possible to jump from the first element to the last element.
    Please explain I'm not able to understand the false case?

    • @nikoo28
      @nikoo28  Před 5 měsíci

      you need to start from the last element, not the first one. watch the explanation that starts at 9:17

  • @singhvishal8794
    @singhvishal8794 Před 5 měsíci +2

    i actually tried this code and come across a wrong ans for [1] as it is reachable at any cost so i run the loop from nums.length -1 to 0 and that worked.... and thank you for this amazing solution i stuck on this for 3 hrs straight...