Minimum Scans to Find All Permutations

Asked at Amazon · Coding & Leetcode-style Questions · Difficulty: Medium

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.

Loading the problem…