Jump Game II
Given an array where each element represents the max jump length, find the minimum number of jumps to reach the end.
Input format
The first line contains N. The second line contains N integers (a[i] ≥ 1, reachable guaranteed).
Output format
Print the minimum number of jumps needed to reach the last index.
Constraints
- Values fit in a 64-bit signed integer
- Trailing whitespace and a trailing newline are ignored by the judge
Read from stdin, write to stdout. Sample cases below show the exact format.
Sample cases
Example 1
Input
5
2 3 1 1 4Expected output
2Example 2
Input
5
2 3 1 1 2Expected output
2