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.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.
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.
readings=[7] → 7
The only entry makes up 100% of the array.
readings is sorted in non-decreasing orderreadings=[3, 5, 5, 5, 8, 9, 11]
5
Run checks the first 3 tests in your browser. Submit checks all 78 tests on the server, hidden ones included.