please tell me where i am wrong i have used this approach which strikes my mind tell me where i am wrong
link:-
Min jump require...------------------
in function there r 2 main variable first is start 2nd is end
in function there r 2 main variable first is start 2nd is end
first iteration I pass 0, array(0)
now I have used loop because we can choose any position to jump from start to end so now I took the next to start and call recursion for it with I+1 , array (i+1)+i+1 and so on and also I keep on adding one to every recursive call and when end reaches greater than or equal to n then store ans.
@riprogerdep hey,your logic is correct but why are you taking 2d array ,just take 1d dp where dp[i] represents minimum no of jumps to reach i from a[0] ,start filling dp from left to right .Here is Pseudo code for reference:
dp[0] = 0;
// Find the minimum number of jumps to reach arr[i]
// from arr[0], and assign this value to jumps[i]
for (i = 1; i < n; i++) {
dp[i] = INT_MAX;
for (j = 0; j < i; j++) {
if (i <= j + arr[j] && dp[j] != INT_MAX) {
dp[i] = min(dp[i], dp[j] + 1);
break;
}
}
}
Hope you get it.
I hope I’ve cleared your doubt. I ask you to please rate your experience here
Your feedback is very important. It helps us improve our platform and hence provide you
the learning experience you deserve.
On the off chance, you still have some questions or not find the answers satisfactory, you may reopen
the doubt.
plz tell me where i am wrong
@riprogerdep bro 2d dp will not work here ,ap i to j ek interval leke uspr solve krrhe ho ,hme sare case consider krne pdenge i to j for every subarray ,to isse acha ap 1-d array leke upr wala explained code dekh lo.
@riprogerdep Build a jumps[] array from left to right such that jumps[i] indicates the minimum number of jumps needed to reach arr[i] from arr[0].
Finally, return jumps[n-1].
Apne i to j sirf pure array ki boundary li hai ,ye mistake hai
bhai poora code dobara likha hai recursive check link
tried on so many cases sabpar sai chalra hai
bro have u checked-----------