Hard
Chemistry Riddles
14 XP

The Majority Element

18,943 solved 71% solve rate 29% fail rate
An array has n elements. One element appears more than n/2 times. You can only compare two elements for equality. How do you find the majority element with O(n) comparisons?
Only 71% solve this correctly
18,943 attempts
Earn +14 XP for solving
Quick Answer & Explanation
Boyer-Moore Majority Vote: maintain

The answer to this riddle is Boyer-Moore Majority Vote: maintain. Difficulty: Hard · Solved by 18,943 puzzle lovers.

Boyer-Moore Majority Vote: maintain a candidate and counter. For each element, if counter is 0, set new candidate. If same as candidate, increment; otherwise decrement. Final candidate is the majority.
🧠 Play Today's Riddle