243. Minimum Jumps
MediumGreedyBFS
From index i you may jump up to a[i] steps forward. Print the minimum number of jumps to reach the last index, or -1 if it is impossible.
Input format
Line 1: n Line 2: n non-negative integers
Output format
The minimum jumps, or -1.
Example 1
Input
5 2 3 1 1 4
Output
2
Example 2
Input
5 2 3 0 1 4
Output
2
Constraints
1 ≤ n ≤ 10⁵
Read input from standard input and print the answer to standard output. Your code is judged against 6 test cases, most of them hidden.
Loading the MyLoginn IDE…