easyArrays & HashingPure DSA~12 min
Majority Flag Vote
A feature-flag service tallies votes from every running pod to decide a single rollout value. Exactly one value won an outright majority — it appears in more than half of the votes. Find it.
Problem
Given an array of integer votes where one value occurs more than ⌊n/2⌋ times, return that majority value.
Input
An array votes of length n (1 ≤ n ≤ 10^5), values in [-10^9, 10^9].
Output
A single integer — the majority value.
Constraints
- 1 ≤ n ≤ 100,000
- A majority element is guaranteed to exist
- Aim for O(1) extra space
Examples
Example 1
Input
votes = [3, 3, 4, 3, 2, 3, 3]
Output
3
3 appears 5 times out of 7, which is more than ⌊7/2⌋ = 3.
Example 2
Input
votes = [9, 9, 9]
Output
9
Single distinct value, trivially the majority.