Skip to main content
All Questions

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.

Related courses

Course

Software Engineering Interview Prep

Land your dream software engineering role at Google, Amazon, Microsoft, Meta, Apple, and other top companies. Learn from mock interviews, frameworks, and advice from senior candidates—practice data structures, algorithms, system design, people management, behavioral interviews, and more.

Course

System Design Interviews

Learn how to answer the latest system design questions across product, infrastructure, and AI domains. Features in-depth video examples, written breakdowns, and helpful reference patterns. Watch senior engineers and managers answer these questions in mock interview videos.