Jump Game II

Practice this coding question on Coding Gurukul.

Problem statement

A robot must reach the final platform using as few forward jumps as possible. Its jump limit is written on each platform. Begin at index zero; any shorter positive jump is allowed. Every input in this exercise has a reachable destination.

Input format

First line: n. Second line: n space-separated integers.

Output format

Print the minimum number of jumps.

Constraints

1 <= n <= 10000; 0 <= jump <= 1000; destination is reachable.

Sample input

5
2 1 3 1 0

Sample output

2

Sign in to run or submit a solution in C++, Java or Python.