#C237. Reorder List Based on Frequency
Reorder List Based on Frequency
Reorder List Based on Frequency
Given a list of integers, rearrange the elements so that those with higher frequencies appear before those with lower frequencies. In the case of a tie (i.e., two numbers appearing with the same frequency), the number that appears first in the original list should come first.
In other words, if an integer x appears more times than integer y, then all occurrences of x should come before any occurrence of y. If x and y appear the same number of times, their original order is preserved in the output.
Your task is to implement a program that reads an integer n followed by n space-separated integers from the standard input, and then prints the reordered list to the standard output. The output should be a single line with the reordered numbers separated by a single space.
The frequency reordering must be implemented such that the algorithm is stable with respect to the original list for elements with equal frequency.
inputFormat
The first line of input contains an integer n, which represents the number of elements in the list.
The second line contains n space-separated integers.
outputFormat
Output a single line with the list of integers sorted according to the criteria mentioned above. The integers should be separated by a single space.
## sample7
4 1 -1 2 -1 2 3
-1 -1 2 2 4 1 3