Jump Game II

Try to solve the Jump Game II problem.

Statement

In a single player jump game, the player starts at one end of a series of squares and aims to reach the last square.

At each turn, the player can take up to ss steps toward the last square, where ss is the value of the current square.

For example, if the value of the current square is 33, the player can take either 33 steps, 22 steps, or 11 steps in the direction of the last square. The player cannot move in the opposite direction, away from the last square.

You’ve been provided with the nums integer array, representing the series of squares.

You’re initially positioned at the first index of the array. Find the minimum number of jumps needed to reach the last index of the array.

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

Constraints

  • 1≤1 \leq nums.length ≤103\leq 10^3

  • 0≤0\leq nums[i] ≤103\leq 10^3

Examples