MicrosoftOA #21
Find Array Uniqueness Median
Estimated HardJudge-ready
Topics (AI-labelled)Binary SearchTwo PointersHashing
Sort the numbers of distinct values of all non-empty contiguous subarrays and return the median; when the length is even, take the smaller of the two middle values.
Input
The first line contains n (1..100000), and the second line contains n integers (1..10⁹).
Output
Output a single integer, the answer.
Example 1
Input:
3
1 2 1
Output:
1
Example 2
Input:
3
1 2 3
Output:
1
Example 3
Input:
2
7 7
Output:
1
Example notes
Example 1: the six counts sorted are 1, 1, 1, 2, 2, 2; take the third one, 1.
Example 2: the six counts sorted are 1, 1, 1, 2, 2, 3; the answer is 1.
Example 3: every subarray contains only one value, so the answer is 1.
Editorial
Loading solution…