#C13101. Most Frequent Integer
Most Frequent Integer
Most Frequent Integer
You are given a list of integers. Your task is to determine the integer that appears the most frequently in the list. If there are multiple integers with the same maximum frequency, output the one that appears first in the list.
Let \( n \) be the number of integers and the list be \( a_1, a_2, \ldots, a_n \). If the frequency of an integer \( x \) is denoted by \( f(x) \), you need to find an integer \( y \) such that \[ f(y) = \max_{1 \leq i \leq n} f(a_i), \] and if there is more than one such integer, choose the one with the smallest index in the list.
If the list is empty (i.e. \( n=0 \)), output None
.
inputFormat
The first line of input contains an integer \( n \) (0 \( \leq n \leq 10^5 \)), which indicates the number of elements in the list. The second line contains \( n \) space-separated integers representing the list elements.
outputFormat
Output the integer that appears most frequently. If the list is empty, output None
.
6
1 2 3 2 1 2
2
</p>