← Questions

Fewest passes to collect a permutation in order

0
AmazonCodingLast asked Jul 2025

A shelf holds a permutation of 1..n. Starting with target 1, you scan the shelf left to right, and whenever you see the current target you take it and look for the next number. When you reach the end you start another pass. Return how many passes it takes to collect every number, in O(n).

Write and test your solution herePython in your browser, the question's tests level by level, every submission kept for you.Sign in to start coding