Find the minimum number of moves to reach the last stall.
Unlock detailed company stats for this questionUpgrade
At a village fair, children start at the first stall and the one who reaches the last stall earliest wins. Each stall displays a token p, letting a child move to any of the next p stalls. Given the token array A = [A1, ..., AN], determine the minimum number of moves needed to get from the first stall to the last (forward moves only).
Input: a single line of space-separated positive integers (the array A), read from STDIN. Output: a single integer, printed to STDOUT with no extra strings.
Constraints: 2 <= N <= 1000, 1 <= Ai <= 100.
Sample 1: A = [4, 4, 2, 1, 4, 4, 1, 2] gives 2 (stall 1 to stall 5 to the last stall). Sample 2: A = [2, 4, 1, 3, 2, 1, 1] gives 3 (e.g., stall 1 to 2 to 6 to the last stall).
Community answers
No answers contributed by the community yet.


