An environmental sensor emits n integer byte readings (each between 0 and 255 inclusive) during a monitoring window. The dashboard needs to display the dominant reading — the value that occurs most often.
If two or more values are tied for the highest frequency, the dashboard always shows the smallest of the tied values (this is the platform's official tie-break rule).
Line 1: an integer n.
Line 2: n space-separated integers, each in [0, 255].
A single integer: the most frequent value, with ties broken by choosing the smallest value.
Example 1
Input
5 3 1 3 2 1
Expected
1
Explanation
3 and 1 both occur twice (the highest frequency); 2 occurs once. Since 3 and 1 tie, the tie-break rule picks the smaller value, 1.
Example 2
Input
4 7 7 7 2
Expected
7
Explanation
7 occurs three times, more than any other value, so it is printed directly.
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 →