Min Operations to Sort All Packages
In an Amazon distribution center, a large number of parcels arrive daily, each assigned a distinct identifier ranging from 1 to n. The warehouse supervisor is tasked with organizing these parcels, but not by their identifiers. Instead, they need to follow a specific order provided by the sortingSequence, which is a permutation of the integers from 1 to n, ensuring the most efficient handling.
Initially, no parcels have been organized (arrangedCount is 0). The supervisor checks the parcels from left to right. If a parcel's identifier matches the next one that needs to be organized (i.e., sortingSequence[i] == arrangedCount + 1), the supervisor arranges it and increments arrangedCount by one. If a parcel's identifier does not match the expected one in the permutation sequence, it is skipped.
Your task is to determine how many complete checks (operations) the supervisor must perform to organize all the parcels. Each operation involves checking all parcels from the first to the last.
Note: A sortingSequence is a valid permutation, meaning it is a sequence consisting of integers from 1 to n, each appearing exactly once. For example, [1, 3, 2] is a valid permutation, while [1, 2, 1] is not.
1Example 1
