#K7056. Sort Array by Frequency
Sort Array by Frequency
Sort Array by Frequency
You are given an array of n integers. Your task is to sort the array based on the frequency of each number in ascending order.
Specifically, let \( f(x) \) denote the number of appearances of \( x \) in the array. The array should be sorted so that if \( f(a) < f(b) \), then \( a \) appears before \( b \). In the case where \( f(a) = f(b) \), the smaller number should come first.
For example, given the array: [4, 5, 6, 5, 4, 3], the number 3 appears once, 6 appears once, 4 appears twice, and 5 appears twice. So, the sorted array is [3, 6, 4, 4, 5, 5].
inputFormat
The input is given as standard input (stdin) and contains two lines:
- The first line contains an integer \( n \) representing the number of elements in the array.
- The second line contains \( n \) space-separated integers.
outputFormat
Output the sorted array as space-separated integers on a single line to standard output (stdout).
## sample6
4 5 6 5 4 3
3 6 4 4 5 5