209. Jump Game II

You are given a 0-indexed array nums of length n representing your maximum jump capability from each index.

You start at index 0. Each element nums[i] represents the maximum number of steps you can jump forward from index i.

Your goal is to reach the last index of the array (nums[n - 1]) using the minimum number of jumps.

Return the minimum number of jumps required to reach the last index.

You can assume that it is always possible to reach the last index.

Example 1:

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

Output: 2

Explanation:

Jump from index 0 → 1 → 4 (2 jumps).

Example 2:

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

Output: 2

Explanation:

Jump from index 0 → 1 → 4.

Now Your Turn!

Pick the correct output for the given input

Input: nums = [5,9,3,2,1,0,2,3,3,1,0,0]

Still unsure what the problem is asking ?

Let’s go through a few more examples, step by step, to make it clearer.

Constraints:

  • 1 <= nums.length <= 10⁴
  • 0 <= nums[i] <= 1000
  • It is guaranteed that you can reach the last index.

Fun Facts

0
class Solution {
public:
int jump(vector<int>& nums) {
// Your code goes here
}
};
Test Case

Input:

Nums