Amazon·Software Engineer·Technical Phone Screen
- You have an array that's a permutation of 1 to n. You scan left to right collecting numbers in order starting from 1, and whenever you hit the end without finishing, you start a new full pass. How many passes does it take to collect everything, and can you do it in O(n)?
“My first instinct was to just simulate it, which works but obviously blows up on time complexity for large inputs.”