Given an array of non-negative integers nums, you are initially positioned at the first index of the array.

Each element in the array represents your maximum jump length at that position.

Your goal is to reach the last index in the minimum number of jumps.

You can assume that you can always reach the last index.

&nbsp;
Example 1:

Input: nums = [2,3,1,1,4]
Output: 2
Explanation: The minimum number of jumps to reach the last index is 2. Jump 1 step from index 0 to 1, then 3 steps to the last index.


Example 2:

Input: nums = [2,3,0,1,4]
Output: 2


&nbsp;
Constraints:


	1 &lt;= nums.length &lt;= 104
	0 &lt;= nums[i] &lt;= 1000


class Solution(object):
    def jump(self, nums):
        ans = l = r = 0

        while r < len(nums) - 1:
            farthestJump = 0

            for i in range(l, r + 1):
                farthestJump = max(farthestJump, i + nums[i])

            l = r + 1
            r = farthestJump
            ans += 1

        return ans
class Solution {

    public int jump(int[] nums) {

        int result = 0;

        int L = 0;
        int R = 0;

        while (R < nums.length - 1) {

            int localMaxRight = 0;

            for (int i=L; i<=R; i++) {

                localMaxRight = Math.max(i + nums[i], localMaxRight);
            }

            L = R + 1;
            R = localMaxRight;
            result++;
        }

        return result;
    }
}
class Solution {
public:
    int jump(vector<int>& nums) {
        int step=0, jump_now;
        int ans = 0, index=0, i, mx;
        if(nums.size()==1) return ans;
        while(index+step<nums.size()-1){
            ans++;
            step = nums[index];
            if(index+step>=nums.size()-1) break;
            mx = 0;
            for(i=1; i<=step; i++){
                if(i+nums[index+i]>mx){
                    mx = i+nums[index+i];
                    jump_now = i;
                }
            }
            step = 0;
            index += jump_now;
        }
        return ans;
    }
};
**//Time Complexity : O(n),   Space Complexity: O(1)**
var jump = function(nums) {
    var jump = 0;
    var prev = 0;
    var max = 0;
    for (var i = 0; i < nums.length - 1; i++) {
        // Keep track of the maximum jump
        max = Math.max(max, i + nums[i]);
        // When we get to the index where we had our previous maximum jump, we increase our jump...
        if (i === prev) {
            jump++;
            prev = max;
        }
    }
    return jump;
};
Jump Game II