Minimum number of Jumps to reach end of an array | Love Babbar DSA Sheet Q10 | Arrays | Jump Game II

Sdílet
Vložit
  • čas přidán 20. 08. 2024
  • ✅ Useful Links
    𝐈𝐧𝐬𝐭𝐚𝐠𝐫𝐚𝐦 - / codingwithprakash
    𝐖𝐡𝐚𝐭𝐬𝐀𝐩𝐩𝐂𝐡𝐚𝐧𝐧𝐞𝐥 - whatsapp.com/c...
    𝐋𝐢𝐧𝐤𝐞𝐝𝐢𝐧 - / prakash-shukla
    SUBSCRIBE AND HIT BELL ICON TO CHECK MORE OF MY CONTENT
    czcams.com/users/Pra...
    Minimum number of Jumps to reach end of an array | Love Babbar DSA Sheet Q10 | Arrays | Jump Game II
    𝐌𝐔𝐒𝐈𝐂 𝐂𝐑𝐄𝐃𝐈𝐓
    Track: Julius Dreisig & Zeus X Crona - Invisible [NCS Release]
    Music provided by NoCopyrightSounds.
    Watch: • Julius Dreisig & Zeus ...
    Free Download / Stream: ncs.io/Invisibl... Complete Crash Course at prakashshukla.com
    Track: Axollo - Silence (ft. Josh Bogert) [NCS Release]
    Music provided by NoCopyrightSounds.
    Watch: • Axollo - Silence (ft. ...
    Free Download / Stream: ncs.io/ASilence

Komentáře • 41

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

    ✅ Useful Links
    𝐈𝐧𝐬𝐭𝐚𝐠𝐫𝐚𝐦 - instagram.com/codingwithprakash/
    𝐖𝐡𝐚𝐭𝐬𝐀𝐩𝐩𝐂𝐡𝐚𝐧𝐧𝐞𝐥 - whatsapp.com/channel/0029VaACtTa4tRrpDCQc5f44
    𝐋𝐢𝐧𝐤𝐞𝐝𝐢𝐧 - www.linkedin.com/in/prakash-shukla/

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

    Hey @Prakash, Using the logic from your another video on "Minimum number of open taps to cover the garden" seemed so natural to me, though it may not be optimized solution for this problem. But want to say thanks for that showing the more intuitive and natural solution. I was able to solve this problem by myself :)
    while(count < Len-1)
    {
    for (int i = 0; i =Len-1)
    return count;
    }

  • @manavkhambhayata6612
    @manavkhambhayata6612 Před měsícem +2

    For GFG :-
    def minJumps(self, arr, n):
    if(n==1):
    return 0
    if(arr[0]==0):
    return -1

    jumps = 0
    pos = 0
    des = 0

    for i in range(0,n-1):
    des = max(des, arr[i]+i)

    if(pos==i):
    pos = des
    jumps +=1
    if(i>=des):
    return -1


    return jumps

  • @satwikjain6177
    @satwikjain6177 Před 2 lety +15

    not working on gfg

  • @harmanjeetsingh3556
    @harmanjeetsingh3556 Před 2 lety +52

    Rehne do yrr mai hi jump maar leta hu.

  • @Barbie_doll566
    @Barbie_doll566 Před 7 měsíci +6

    Heee Bhagwan utha le muzhee😢😭😭

  • @Ocean_77848
    @Ocean_77848 Před 10 měsíci +3

    For gfg test case need two modification , when having zero in the array ,
    def minJumps(self, arr, n):
    #code here
    j=0;d=0;p=0
    if arr[0]==0:return -1
    for i in range(n-1):
    d=max(d,arr[i]+i)
    if i>=d:
    return -1
    if p==i:
    p=d
    j=j+1
    return j
    where j = iump,d=destination,p=position

    • @sahebullah2194
      @sahebullah2194 Před 10 měsíci +1

      Thanx a lot friend 👍👍
      It worked

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

      not working,test cases passed: 1109 /1113

  • @e_27_devenkalathiya94
    @e_27_devenkalathiya94 Před rokem +3

    class Solution{
    static int minJumps(int[] arr){
    // your code here
    int count=0,current=0,max=0;
    for(int i=0;i=arr.length-1)
    break;
    else if(max

  • @user-xe7jk3rc4w
    @user-xe7jk3rc4w Před rokem +1

    This is giving TLE although working very good in the local Enviroment:
    int jump = 0;
    for(int i = 0; i< arr.length; i=(i+arr[i])){
    if(arr[i] == arr.length){
    return -1;
    }else{
    jump++;
    }
    }
    return jump;

  • @parthantal3384
    @parthantal3384 Před rokem +6

    Excellent approach bro. Thank you.

  • @devmadaan5146
    @devmadaan5146 Před 17 hodinami +1

    Why the fck do i have to habdle edge cases like n=0 , divthe question setter , did not understand this...like why is he at first giving me the question, is like generating a problem, then the solution.
    Main thing lies is system fldesign in dev world, but still we are fcking here

  • @kumarlakshya4407
    @kumarlakshya4407 Před 2 lety +6

    yrr itnna kaissee sochhuuu

  • @MilindGupta
    @MilindGupta Před 2 lety +1

    Solution kaafi sahi thaa waise yeh

  • @nimish3367
    @nimish3367 Před 2 lety +1

    Incase question suggests that we have to return -1 if we cant reach the end. Here is the modified soln'
    int Solution::jump(vector &A) {
    int n=A.size();
    int jump=0;
    int pos=0;
    int des=0;
    for(int i=0;i

    • @gumanrathore4351
      @gumanrathore4351 Před 2 lety

      This solution doesn't works on gfg try again

    • @ShubhamSingh-jj1up
      @ShubhamSingh-jj1up Před 2 lety +1

      @@gumanrathore4351 Here is the correct solution with '0' present in array :
      class Solution{
      static int minJumps(int[] arr){
      if(arr[0] == 0 && arr.length > 1) {
      return -1;
      }
      int maxReachable = 0;
      int currPos = 0;
      int jump = 0;
      int i = 0;
      for(; imaxReachable)
      return -1;
      return jump;
      }
      }

    • @yourguy9785
      @yourguy9785 Před rokem +1

      @@ShubhamSingh-jj1up bro ......you saved my hours to be ruined

  • @ashutoshranjan5098
    @ashutoshranjan5098 Před 2 lety +1

    Thank you so much bhaiya

  • @AbhishekKumar-qz6jv
    @AbhishekKumar-qz6jv Před 2 lety +6

    Can you give the code of graph solution

  • @pranjalgusain21
    @pranjalgusain21 Před rokem +10

    handle 0 with this condition in for loop: if( i == pos && arr[pos] == 0 && pos == des) return -1;
    whole code will look like:
    static int minJumps(int[] arr){
    int des = 0;
    int pos = 0;
    int jump = 0;
    for(int i = 0; i

    • @bubbit
      @bubbit Před rokem +3

      you saved me 😭, ive been trying to understand this shitty problem for very long

  • @mightygamers7951
    @mightygamers7951 Před rokem +3

    Bro this solution doesn't work on gfg

    • @amit2194
      @amit2194 Před rokem +1

      kunki inhone 1 step me better answer milte hi update kr diya
      what if 3 4 step k bad better answer mile

  • @gumanrathore4351
    @gumanrathore4351 Před 2 lety +3

    Sir pls give solution in comment section for case 0 I tried to modify it but it's not working

    • @CodingWithPrakash_
      @CodingWithPrakash_  Před 2 lety

      Telegram grp pe aa jao
      Vaise is edge case ko homework man lo aur khud try kro varna telegram pe krte hai discuss

  • @mohdabbas8307
    @mohdabbas8307 Před 2 lety +1

    sir dp ki kab resume kroge playlist ?

  • @azimuddin6921
    @azimuddin6921 Před rokem

    nice bhai

  • @krishnaraju8997
    @krishnaraju8997 Před rokem

    Why u r adding index?.. Plz let me know very confused

  • @PrakharSingh0301
    @PrakharSingh0301 Před rokem +1

    Its not working for var arr = [1, 2, 0, 0, 5];
    Can anyone fix this

    • @parthantal3384
      @parthantal3384 Před rokem +3

      bro you have to handle this case as a base case like: if(arr[i]==0) return Integer.MAX_VALUE because you will be stuck forever when arr[i]=0 meaning you cannot jump anywhere.