← 返回 amazon 的题目列表Minimum Scans to Find All Permutations
类型:online_judge
Given an array that is a permutation of numbers 1 to n, calculate the minimum number of scans from left to right needed to find all numbers completely. Each round is a scan from left to right. If the current number to find is x and it is found during the scan, then start looking for x+1. Initially, start with number 1. The algorithm needs to be O(n) in time complexity.
Example
Input
[1, 2, 3, 4]