Problem 279408 · easy · Phase 02 Linear Data Structures

Majority Vote

arrays · counting · iteration

votes lists the candidate id chosen by each voter. A candidate wins outright if they received more than half of all votes. Return the winning candidate id, or None if nobody has a strict majority (including when there are no votes).

Examples

Input:  votes = [3, 3, 4, 3]
Output: 3
Explanation: 3 appears 3 times out of 4.

Input:  votes = [1, 2, 1, 2]
Output: None
Explanation: Nobody has more than 2 of the 4 votes.

Constraints

  • 0 <= len(votes) <= 10**5
  • Target: O(n) time.

Goals

  • Count occurrences with a dictionary or Counter
  • Apply a strict 'more than half' threshold
  • Return None when no candidate qualifies
Starting Python…