Top down Approach for this question


#1

int find(vector &dp, vector &A, int i){
if(i >= A.size()-1) return 1;
if(dp[i]!=-1) return dp[i];

int ans = 0;
for(int j=1; j<=A[i]; j++){
    ans = ans|find(dp,A,i+j);
    if(ans) break;
}

dp[i] = ans;
return ans;

}

int Solution::canJump(vector &A) {
int n = A.size();
vector dp(n,-1);

if(find(dp,A,0)) return 1;
return 0;

}