Jump Game II

MediumGreedy
Next
GreedyArrayBFS

Same setup as Jump Game, but the last index is guaranteed to be reachable. Find the minimum number of jumps needed to get from the first index to the last.

Input

Line 1: n. Line 2: n non-negative integers.

Output

Print the minimum number of jumps.

Constraints

1 <= n <= 10^4 0 <= each value <= 1000 The last index is always reachable.

Example 1
Input
5
2 3 1 1 4
Output
2

Jump to index 1, then to the last index: 2 jumps.

Hints

Jump Game II - Medium Greedy Problem | Skill Shiksha