80. Sort by Frequency
MediumSortingHash Map
Sort the values by decreasing frequency; values with equal frequency go in increasing order. Print the full sorted array (repeated values stay repeated).
Input format
Line 1: n Line 2: n integers
Output format
The array sorted by frequency.
Example 1
Input
6 2 5 2 8 5 6
Output
2 2 5 5 6 8
Example 2
Input
5 1 1 1 3 3
Output
1 1 1 3 3
Constraints
1 ≤ n ≤ 10⁵
Read input from standard input and print the answer to standard output. Your code is judged against 6 test cases, most of them hidden.
Loading the MyLoginn IDE…