Problem statement
You are given an array where one value appears more than half of the time. Find that value.
The intended solution makes one pass over the array and keeps only two small variables, no map and no sorting.
Examples
Input[3, 2, 3]
Output3
3 appears twice out of three values, which is more than half.
Input[2, 2, 1, 1, 1, 2, 2]
Output2
2 appears four times out of seven.
The walkthrough is part of Premium
The statement and the examples above stay free. The full how-to-solve walkthrough, the cost notes in plain words and the interactive step-by-step visualizer unlock with a Premium plan.
See pricing