Ctrl K

Majority in a Sorted List

Easy
The scores of a contest's participants are listed in ascending order in the array scores (equal scores sit next to each other). You are also given a number value. Return True if **more than half** of the participants scored value, that is, it occurs in scores strictly more than len(scores) / 2 times. Otherwise return False. The array is already sorted; think about how to use that instead of scanning all of it.
Example 1
scores=[3, 7, 7, 7, 7, 9], value=7 → True

7 appears 4 times out of 6, which is more than half.

Example 2
scores=[2, 2, 5, 5], value=5 → False

5 appears exactly 2 times out of 4: that is exactly half, and strictly more is required.

Example 3
scores=[1, 4, 4, 8, 8], value=6 → False

The value 6 is not in the list at all.

Constraints
  • 1 ≤ len(scores) ≤ 1000
  • 1 ≤ scores[i], value ≤ 10⁹
  • scores is sorted in non-decreasing order
Have you seen this problem in a real interview?
Solved by0
Tried by0
Submissions0
Acceptance—
Topics
Similar problemsSlot on a Sorted Shelf EasyThe Lost Ticket EasyValues in Both Lists EasyShared Values With Repeats EasyFind in a Sorted List Easy
loading Python…
Input
scores=[3, 7, 7, 7, 7, 9], value=7
Expected
True

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