Determine how many tasks George can finish before a round ends, given a sequence of task positions and a rule that processes them in increasing order of appearance.
Problem
George has a list of tasks arranged in an array. He wants to process them in a round where tasks are handled in a specific order based on their positions. Your job is to determine how many tasks can be completed before the round finishes under the given processing rule.
A practical way to think about the problem is that George must scan the array, keep track of which required positions have been reached, and count the work completed in the correct order.
Goal
Compute the final count according to the rule described by the input sequence.
Input Format
- The first line contains an integer .
- The second line contains integers describing the array.
Output Format
- Print one integer: the answer for the round.
Constraints
- Array values fit in 32-bit signed integers
- Time complexity should be near linear or
Hints
- Track the positions you care about while scanning the array once.
- Sorting or counting may help depending on how the order is enforced.
Input Format
- Integer
- Array of integers
Output Format
- A single integer answer
Constraints
- Use an approach efficient enough for large arrays
Example 1
Input
5 1 3 2 5 4
Output
5
Explanation
All elements can be processed in the required order, so the total count is 5.
Example 2
Input
4 2 1 4 3
Output
4
Explanation
The scan still allows all required elements to be completed by the end of the round.
Premium problem context
Unlock deeper context for this problem
Premium adds guided hints, editorial links, similar variants, discussion resources, and concept maps so you can understand why a problem matters, not just solve it once.