You are given an array of n integers. Find the value that appears the greatest number of times. If two or more values share the greatest count, print the smallest such value.
Line 1: an integer n.
Line 2: n space-separated integers, the array.
A single integer: the mode (smallest value among those with the highest frequency).
Example 1
Input
5 1 2 2 3 3
Expected
2
Explanation
Values 2 and 3 each appear twice (the maximum). On the tie, the smaller value 2 is printed.
Example 2
Input
4 7 7 7 1
Expected
7
Explanation
The value 7 appears three times, more than any other, so the mode is 7.
Ready to solve this?
Sign in to open the editor, run your code against the sample tests, and submit against the full test suite.
Sign in to solve →