#C8312. Smallest Most Frequent Element
Smallest Most Frequent Element
Smallest Most Frequent Element
Given an array of integers ( A = [a_1, a_2, \dots, a_n] ), determine the element that occurs most frequently. In the event of a tie (i.e. multiple elements have the same maximum frequency), output the smallest among those.
Formally, let ( f(x) ) be the frequency of ( x ) in ( A ). Find ( x^* ) such that ( f(x^) = \max_{x \in A} f(x) ) and for any ( x ) with ( f(x) = \max_{x \in A} f(x) ), ( x^ \le x ).
inputFormat
The input is read from standard input (stdin). The first line contains a single integer ( n ) representing the number of elements in the array. The second line contains ( n ) space-separated integers representing the elements of the array.
outputFormat
Output a single integer to standard output (stdout): the smallest integer that has the highest frequency in the array.## sample
7
4 5 6 6 7 4 4
4