306. Most Frequent, Smallest Wins
Print the value that appears most often. If several values tie for the highest count, print the smallest of them.
The tie rule is what makes this a definite question rather than an ambiguous one. Without it, any of the tied values would be a valid answer and no judge could check it.
Count everything, then take a single pass over the distinct values keeping the best so far: strictly higher count wins, and an equal count wins only if the value is smaller.
Constraints - `1 ≤ n ≤ 200000` - `-1000000000 ≤ a[i] ≤ 1000000000`
Input
The first line contains an integer n.
The second line contains n integers.
Output
Print one integer, the most frequent value, smallest on a tie.
Hints
Four rungs, in order. The last two open once you have submitted an attempt. A wrong one counts.