Minimum Jumps To End of Array | Optimal O(1) space O(N) Time approach |Dynamic Programming |🚀🌟

Поділитися
Вставка
  • Опубліковано 28 жов 2024

КОМЕНТАРІ • 45

  • @auctal4625
    @auctal4625 4 роки тому +25

    Man, your solutions are way more simpler to understand than any other solutions available on internet.
    Most of them copy from geeks for geeks and we need Big brain to understand those.

  • @codestorywithMIK
    @codestorywithMIK 4 роки тому +11

    Very good solution. Just one thing to add, you missed to check if stepsPossible becomes < 0 after line number 29. i.e. your solution will give wrong answer for this test case below :
    5
    0 1 1 1 1
    So, just add one more check: if(stepsPossible < 0) return -1;
    It will work fine. Thanks again for this concept. Loved it.

  • @dharanyuvi6951
    @dharanyuvi6951 3 роки тому +2

    Explaining this algorithm is not a cup of tea for everyone
    But you nailed it man
    credits to you.!!

  • @surajmaharana2608
    @surajmaharana2608 3 роки тому +3

    Very helpful video. Not many show such visualization and bcos of this visualization, I understood y maxReach - i. Also, not many use Vim. Glad to see another vim user. I'm sure by now, you might have learnt better way to navigate Vim.
    And this video was so easy to understand and helpful. Thanks :)

  • @anjana1700
    @anjana1700 4 роки тому +1

    Sir, if maxReachable exceeds n-1, why don't we return then and there. This way we may not need to run for loop till i

  • @deeptishukla7761
    @deeptishukla7761 3 роки тому +1

    I liked your idea, very helpful to see you solved a problem from brute-force to most optimal solution.

  • @sanjayraghavendra3628
    @sanjayraghavendra3628 4 роки тому +6

    Hey bro, videos are really beginner-friendly. Gave a nice idea on how to approach such problems. Keep posting such quality contents

  • @rahulagrawal3611
    @rahulagrawal3611 3 роки тому +2

    I couldn't get why jump begins from 1? arr[0] is 1 so going to arr[1] seems a step not jump. Jump is something when currently we don't have step. If we consider an array like {5,2,4,1} we need not any jump here, isn't ?

  • @parrotsparadise3914
    @parrotsparadise3914 2 роки тому +1

    Good explanation vro!
    You can optimise a bit by
    if(maxReach>=(n-1))
    return jumps+=1;
    So we need not to go till i==n-1

  • @kumaiyavlogs5020
    @kumaiyavlogs5020 3 роки тому +1

    What if
    Using maxreachable we are not reaching the n-1
    And some other value lower then maxreachable is taking us to the n-1

  • @hemantagarwal5095
    @hemantagarwal5095 3 роки тому +8

    this background noise is so irritating, it distracts very much :(

  • @lukefran9442
    @lukefran9442 4 роки тому +5

    I see you use Vim too , finally a man of culture.

    • @rithikraj1813
      @rithikraj1813 3 роки тому

      I smell Madox here.....😂😂 But yeah he is man of culture

  • @shashanksarma4096
    @shashanksarma4096 3 роки тому +1

    Reallly Good Solution! Saw the same kind of solution on GFG but couldnt understand why steps= maxReachable -i ; This cleared it Up. Thanks g

  • @asibrahim2780
    @asibrahim2780 4 роки тому +2

    Thank you for this demo. But please may I ask you one question : I have tried to solve this array but it does not giving me the good solution : int arr[] = {1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1}; jumps must to be 10, but it gives 11

    • @rounakkumarkedia5826
      @rounakkumarkedia5826 4 роки тому +2

      because he is considering reaching the first element as 1 .. in your ques..it might be that we start from pos 1(index 0)

  • @greatab2977
    @greatab2977 3 роки тому

    Great explanation

  • @sumandas5563
    @sumandas5563 3 роки тому

    this was very helpful, very good exaplanation.

  • @piyushkumar-wg8cv
    @piyushkumar-wg8cv 2 роки тому

    Why can't we re-initialise, steps = arr[i] instead of steps = maxReachable - i (according to your code)

  • @lochannatesh6684
    @lochannatesh6684 3 роки тому

    neat and crisp explanation keep it up!!!

  • @nikhil6842
    @nikhil6842 4 роки тому

    better than the paid contents.
    I just have one query, I was able to come up with recursive and bottom up dp on my on.
    how do I come up with O(n) solutions. seeing it makes it obvios, but how do we take a dp sol say, and then reduce complexity further.
    Anyways, great conent, subscribed and liked.
    Pls reply , getting started with recusrsion and dp.

  • @smilingassasin7227
    @smilingassasin7227 3 роки тому

    great expalanation bro

  • @pranaynegi6689
    @pranaynegi6689 4 роки тому

    One thing I'm still not getting is that why we need 3 jumps when we can directly jump from ele 3 to ele 9 and only 2 jumps are required.
    Geeks for Geeks showed sol. Like
    (1->3->8->9 )
    3 jumps didn't get this part
    Please help buddy

  • @divyanubaheti7343
    @divyanubaheti7343 3 роки тому

    I dint quit get why r we decreamenting steps.Can anyone help???????

  • @harshvardhanshingade1068
    @harshvardhanshingade1068 3 роки тому

    first condition is missed if arr[0] == -1 edge case

  • @wemake4u444
    @wemake4u444 3 роки тому

    Nice Explanation

  • @RahulRoy-wo9dg
    @RahulRoy-wo9dg 3 роки тому

    adding "if (arr[0] == 0) return -1;" at the beginning of the function will pass the testcase 0 1 1 1 1

  • @vaibhavaggarwal6808
    @vaibhavaggarwal6808 3 роки тому +1

    it's not Dp its greedy Dp is working in O(n^2)

  • @rohitchandekar2477
    @rohitchandekar2477 3 роки тому

    isaka koi intuition bata skata h ya

  • @aaryamansharma6805
    @aaryamansharma6805 4 роки тому

    awesome video bro .... Thank you ...... subscribed now ..... hope you make more good explanation videos like this.

  • @whynesspower
    @whynesspower 3 роки тому +1

    this one is not the dynamic programming approach but the greedy approach. Kindly correct on title

    • @whynesspower
      @whynesspower 3 роки тому

      or correct me if I'm wrong and this is the dynamic approach itself XD

    • @aayushisingh3280
      @aayushisingh3280 3 роки тому

      @@whynesspower you are right. this is greedy and not DP

  • @gurupreetsingh8347
    @gurupreetsingh8347 3 роки тому

    arre bhai background music toh band kar lo

  • @namanchoudhary592
    @namanchoudhary592 4 роки тому +1

    very helpful mam