AmazonOA #61
Get Number Operations (Package Sorting Passes)
Estimated EasyJudge-ready
Topics (AI-labelled)HashingIn-place Arrays
You are given a permutation of 1..n. In each round, scan from left to right and process the next not-yet-processed number as soon as you reach it; several numbers can be processed in a row within one round. Find how many rounds are needed to process all numbers.
Input
The first line contains n (1..1000000), and the second line contains a permutation of 1..n.
Output
Output a single integer answer.
Example 1
Input:
5
5 3 4 1 2
Output:
3
Example 2
Input:
1
1
Output:
1
Example 3
Input:
3
3 2 1
Output:
3
Example notes
Example 1: the first round processes 1, 2; the second 3, 4; the third 5, so the answer is 3. Example 2: a single scan finishes. Example 3: each round can process only one number, so the answer is 3.
Editorial
Loading solution…