AmazonOA #365
Find Median of Subarray Uniqueness
Estimated HardJudge-ready
Topics (AI-labelled)Binary SearchTwo PointersHashing
For every non-empty contiguous subarray, compute its number of distinct values, and sort all these numbers; when their count is even, take the smaller of the two middle numbers. Find this lower median.
Input
The first line contains n and the second line contains n numbers. The complete original bounds are in the body: 1≤n≤100000, 1≤a[i]≤n; they are not overridden by the N/A placeholder at the end.
Output
Output a single integer, the answer.
Example 1
Input:
2
1 1
Output:
1
Example 2
Input:
3
1 2 3
Output:
1
Example 3
Input:
3
1 2 1
Output:
1
Example notes
The outputs of the three public examples are 1; 1; and 1, checked by independent enumeration or direct simulation.
Editorial
Loading solution…