What is the error with my recursive code?
What is the error with my recursive code?
Code failed in one test case
@ap8730390 code is fine
public static long MJRTD(long [] arr, int i, long[] strg){
// pehle ye aayega
if(i >= arr.length-1){
return 0;
}
// Then
if(arr[i]== 0){
return (long) Integer.MAX_VALUE;
}
if(strg[i]!=-1){
return strg[i];
}
long minJumps = Integer.MAX_VALUE;
for(int j= i+1;j< arr.length && j<=i+arr[i] ; j++){
long jumps = MJRTD(arr,j,strg);
if(jumps!= Integer.MAX_VALUE && jumps +1 < minJumps){
minJumps = jumps + 1;
}
}
strg[i]= minJumps;
return minJumps;
}
1 Like