Ctrl K

The Quarter-Heavy Value

Easy
A greenhouse thermometer logged its readings into the array readings, which is already sorted in non-decreasing order. Exactly one value occurs in more than a quarter of all entries (strictly more than 25%). Return that value. Counting how often each value occurs is easy; think about how the sorted order can help.
Example 1
readings=[3, 5, 5, 5, 8, 9, 11] → 5

The length is 7, so a quarter is 1.75. The value 5 appears three times; every other value appears once.

Example 2
readings=[4, 4, 4, 9, 9, 12, 15, 17, 20, 21] → 4

The length is 10, so a quarter is 2.5. The value 4 appears 3 times, which is more than that; 9 appears only twice, which is not.

Example 3
readings=[7] → 7

The only entry makes up 100% of the array.

Constraints
  • 1 ≤ len(readings) ≤ 10⁴
  • 0 ≤ readings[i] ≤ 10⁵
  • readings is sorted in non-decreasing order
  • Exactly one value occupies strictly more than 25% of the positions
Have you seen this problem in a real interview?
Solved by0
Tried by0
Submissions0
Acceptance—
Topics
Similar problemsPair With a Target Sum EasySqueeze Repeats Out of a Sorted Array EasyDrop the Unwanted Value EasySlot on a Sorted Shelf EasyAdd One to a Digit Array Easy
loading Python…
Input
readings=[3, 5, 5, 5, 8, 9, 11]
Expected
5

Run checks the first 3 tests in your browser. Submit checks all 78 tests on the server, hidden ones included.