<p>You are given an integer array <code>nums</code>. You are initially positioned at the array&#39;s <strong>first index</strong>, and each element in the array represents your maximum jump length at that position.</p>

<p>Return <code>true</code><em> if you can reach the last index, or </em><code>false</code><em> otherwise</em>.</p>

<p>&nbsp;</p>
<p><strong class="example">Example 1:</strong></p>

<pre>
<strong>Input:</strong> nums = [2,3,1,1,4]
<strong>Output:</strong> true
<strong>Explanation:</strong> Jump 1 step from index 0 to 1, then 3 steps to the last index.
</pre>

<p><strong class="example">Example 2:</strong></p>

<pre>
<strong>Input:</strong> nums = [3,2,1,0,4]
<strong>Output:</strong> false
<strong>Explanation:</strong> You will always arrive at index 3 no matter what. Its maximum jump length is 0, which makes it impossible to reach the last index.
</pre>

<p>&nbsp;</p>
<p><strong>Constraints:</strong></p>

<ul>
	<li><code>1 &lt;= nums.length &lt;= 10<sup>4</sup></code></li>
	<li><code>0 &lt;= nums[i] &lt;= 10<sup>5</sup></code></li>
</ul>

// You are given an integer array nums. You are initially positioned at the arrays first index, and each element in the array represents your maximum jump length at that position.

// Return true if you can reach the last index, or false otherwise.
// nums = [2,3,1,1,4]
//     take 2 then jump two indi
//         at indi 2 val =1 then jump 1
//         at indi 3 val =1 then jump 1
//         at indi 4 which is last element;
//         true
    
//     fun=i+nums[i]



class Solution {
public:
    bool fun(int i,vector<int>&nums,vector<int>&dp){
        if(i==nums.size()-1){
            return true; 
        }else if(i>=nums.size() && nums[i]==0){
            return false;
        }
        if(dp[i]!=-1){
            return dp[i];
        }
       
        for(int j=i+1;j<=(nums[i]+i);j++){
           if(fun(j,nums,dp)){
               return dp[i]=true;
           }
           
        }
        return dp[i]=false;
    }
    bool canJump(vector<int>& nums) {
        vector<int>dp(nums.size(),-1);
        return fun(0,nums,dp);    
    }
};
54100