#B4296. Minimum Jumps for the Frog
Minimum Jumps for the Frog
Minimum Jumps for the Frog
There are N wooden stakes arranged in a row. Each wooden stake has a number on it which represents the maximum number of wooden stakes that a frog can jump ahead in one move (for example, if the number on a stake is $2$, the frog can jump either $1$ or $2$ stakes ahead).
The problem is to calculate the minimum number of jumps needed for the frog to get from the first stake to the last stake.
Note: If the frog is already on the last stake, the number of jumps is $0$.
The jump length options available from a stake with value $a_i$ is any integer from $1$ to $a_i$ inclusive.
inputFormat
The first line contains an integer $N$ ($1 \leq N \leq 10^5$) representing the number of wooden stakes. The second line contains $N$ space-separated integers, where the $i$-th integer represents the number on the $i$-th stake.
outputFormat
Output a single integer representing the minimum number of jumps required to reach the $N$-th stake from the first stake.
sample
5
2 1 5 1 3
2