#K65307. Find the Mode in an Integer Array
Find the Mode in an Integer Array
Find the Mode in an Integer Array
In statistics, the ( \textbf{mode} ) of a dataset is the value that appears most frequently. Given an array of integers, your task is to find its mode. If there is a unique mode, output that single integer. If there are multiple modes (i.e. several numbers have the same highest frequency), output all of them in ascending order.
Input Format:
The first line contains an integer ( n ), representing the number of elements in the array. The second line contains ( n ) space-separated integers.
Output Format:
If the array has a unique mode, print that integer. Otherwise, print the sorted list of modes separated by a single space.
Example:
For the input:
5
1 2 2 3 4
The output should be:
2
inputFormat
The input will be provided through standard input (stdin). The first line contains an integer ( n ) which indicates the number of elements. The second line contains ( n ) space-separated integers.
outputFormat
Print the mode of the array. If there are multiple modes, print them in ascending order separated by a single space, all through standard output (stdout).## sample
5
1 2 2 3 4
2