#C12671. Most Frequent Element
Most Frequent Element
Most Frequent Element
Given an array of integers, find the element that appears most frequently. In case of a tie, output the smallest element. Formally, for an array ( A = [a_1, a_2, \ldots, a_n] ), you need to determine the value ( x ) such that its frequency ( f(x) ) is maximized, and if there are multiple such elements, choose the minimum one.
inputFormat
The first line contains an integer ( n ) representing the number of elements. The second line contains ( n ) space-separated integers. Note that if ( n = 0 ), the input is considered empty.
outputFormat
Output the most frequent element among the array. In the case of a tie, output the smallest element. If the input list is empty (i.e. ( n = 0 )), output exactly “ValueError”.## sample
10
4 1 2 2 3 3 3 4 4 4
4