Element Appearing More Than 25% In Sorted Array

Easy

Description

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.

Examples

Input:arr = [1,2,2,6,6,6,6,7,10]
Output:6
Explanation:

6 appears 4/9 > 25%.

Input:[3,3,3,3,5,5,8]
Output:3
Explanation:

3 appears 4 times out of 7 total elements. 4/7 ≈ 0.571 which is greater than 25%.

Input:[1,1,1,2,3,4,5,6]
Output:1
Explanation:

1 appears 3 times out of 8 total elements. 3/8 = 0.375 which is greater than 25%. No other element appears more than once.

Constraints

  • 1 ≤ arr.length ≤ 10⁴

Ready to solve this problem?

Practice solo or challenge other developers in a real-time coding battle!