Problem 825
Element Appearing More Than 25% in a Sorted Array
Easy · 10 pts · Array, Binary Search
Problem
The array is sorted in non-decreasing order, and exactly one value appears more than 25% of the time, that is, more than N / 4 times. Print that value. Because the array is sorted, equal values sit together, so a value with more than N / 4 copies satisfies A[i] = A[i + floor(N / 4)] for some i. A single scan over i finds it.
Input
The first line contains an integer N, the size of the array. The second line contains N space-separated integers A[0], A[1], ..., A[N-1]. The array is sorted and exactly one value appears more than N / 4 times.
Output
Print the value that appears more than 25% of the time.
Constraints
1 <= N <= 100000; 0 <= A[i] <= 10^5
Example input
9 1 2 2 6 6 6 6 7 10
Example output
6
Explanation
In 1 2 2 6 6 6 6 7 10 (N = 9), the value 6 appears 4 times, which is more than 9 / 4 = 2.25. So the answer is 6.