Using standard DP procedure, getting a segmentation fault, looking for help


#1

vector dp ;

int solve(vector& A,long long int x){
if(x<0 || x>=A.size()) return 0 ;
if(dp[x]!=-1) return dp[x] ;
for(long long int i=1;i<=A[x] && x+i<A.size();i++)
if(solve(A,x+i)){
dp[x]=1 ; return 1 ;
}
dp[x]=0 ;
return 0 ;
}

int Solution::canJump(vector &A) {
dp.clear() ;
if(A.size()==0) return 0 ;
dp.resize(A.size()) ;
for(long long int i=0;i<A.size();i++) dp[i]=-1 ;
dp[A.size()-1]=1 ;
return solve(A,0) ;
}


#2

The depth of the recursive calls in your solution is likely causing the issue, try using Iterative DP or a greedy approach