#C14766. Frequency Sort
Frequency Sort
Frequency Sort
You are given a list of n integers. Your task is to sort the list based on the frequency of each integer in descending order. In case two integers have the same frequency, the smaller number should come first (i.e. in ascending order).
More formally, let \( f(x) \) denote the frequency (number of occurrences) of integer \( x \) in the list. Then, the list should be sorted in such a way that for any two numbers \( a \) and \( b \):
\( f(a) > f(b) \) or \( (f(a) = f(b) \text{ and } a < b) \).
The input will be provided via standard input and the output should be printed to standard output.
inputFormat
The first line contains an integer n, representing the number of elements in the array. The second line contains n integers separated by spaces.
Example:
9 4 3 1 6 4 7 1 4 7
outputFormat
Output the sorted list of integers based on their frequency (and numerical order in case of ties), with each integer separated by a single space.
Example:
4 4 4 1 1 7 7 3 6## sample
9
4 3 1 6 4 7 1 4 7
4 4 4 1 1 7 7 3 6