[Solution] Remove Prefix Codeforces Solution
Polycarp was presented with some sequence of integers of length (). A sequence can make Polycarp happy only if it consists of different numbers (i.e. distinct numbers).
In order to make his sequence like this, Polycarp is going to make some (possibly zero) number of moves.
In one move, he can:
occupied
- remove the first (leftmost) element of the sequence.
For example, in one move, the sequence will produce the sequence , which consists of different numbers.
Determine the minimum number of moves he needs to make so that in the remaining sequence all elements are different. In other words, find the length of the smallest prefix of the given sequence , after removing which all values in the sequence will be unique.
The first line of the input contains a single integer () — the number of test cases.
Each test case consists of two lines.
The first line contains an integer () — the length of the given sequence .
The second line contains integers () — elements of the given sequence .
It is guaranteed that the sum of values over all test cases does not exceed .
For each test case print your answer on a separate line — the minimum number of elements that must be removed from the beginning of the sequence so that all remaining elements are different.
No comments:
Post a Comment