Element Appearing More Than 25% In Sorted Array
Solve this the way you would in the interview: out loud, on a timer, with an AI interviewer asking follow-ups while you code. You get a scored report at the end.
Practice this as a mock interviewFree to start, no account neededProblem
You are given an integer array arr sorted in non-decreasing order. Exactly one value in it occurs strictly more than 25% of the time (more than arr.length / 4 occurrences).
Return that value.
A linear scan works; the sorted order also allows an O(1)-extra-space check that compares each element with the one a quarter of the array ahead.
Examples
Constraints
- 1 <= arr.length <= 10^4
- 0 <= arr[i] <= 10^5 (tests may also use negatives)
- `arr` is sorted in non-decreasing order.
- Exactly one value occurs more than `arr.length / 4` times.
What the interviewer grades
A correct solution is one of five scores. The report also grades problem understanding (did you clarify inputs and edge cases before coding), problem solving, communication while you work, code quality, and testing. See a sample report, or read up on the pattern in the lessons.