Amazon·Software Engineer·Onsite - Coding / Algorithms
- Given an array that is a permutation of 1 through n, you scan left-to-right looking for consecutive integers starting from 1. Each time you find the current target you increment it and keep going in the same pass. When you hit the end, if you haven't found everything yet, you restart from the beginning. How many full passes does it take to find all n numbers?
“My first instinct was to just simulate it, and that works fine for small inputs, but I had a feeling they wanted something better.”