Majority Element — Boyer-Moore voting
Hold one candidate and a running count. A matching value is a vote for it, a different value a vote against. When the count hits zero, the next value becomes the new candidate. The majority always survives.
Try:
← Prev
Next →
▶ Play
Reset
candidate
—
count
0