Given an integer array sorted in non-decreasing order, there is exactly one integer in the array that occurs more than 25% of the time, return that integer.
Given an integer array sorted in non-decreasing order, there is exactly one integer in the array that occurs more than 25% of the time, return that integer.
Example 1:
Input: {"arr":[1,2,2,6,6,6,6,7,10]}
Output: 6
Constraints:
1≤arr.length≤104
0≤arr[i]≤105
Test Cases
Input (Stdin)
Expected Output (Stdout)
Execution Result
Run code to see results.
Input
arr ={"arr":[1,2,2,6,6,6,6,7,10]}
n = 9, so step = n // 4 = 2. A value appearing more than 2.25 times fills at least 3 cells in a row, so it covers both ends of any ruler of that length placed on its first copy.
the sorted array as runs of equal values (width = count); the orange ruler spans step + 1 = 3 cells, just over a quarter