AmazonOA #344
Sort Error Codes by Frequency
Estimated EasyJudge-ready
Topics (AI-labelled)HashingIn-place Arrays
Keep every element of the array, sorting first by total number of occurrences in ascending order and, for equal frequencies, by value in ascending order; duplicate values cannot be removed.
Input
The first line contains n and the second line contains n integers. The original statement only gives the sorting rule, with no value bounds; on this site 0≤n≤200000 and elements are in −10^9..10^9.
Output
Output the n integers in the required order, separated by spaces; when n=0, output an empty line.
Example 1
Input:
6
4 5 6 5 4 3
Output:
3 6 4 4 5 5
Example 2
Input:
6
2 2 1 1 1 3
Output:
3 2 2 1 1 1
Example 3
Input:
0
Output:
Example notes
The outputs of the three public examples are 3 6 4 4 5 5; 3 2 2 1 1 1; and an empty line, checked by independent enumeration or direct simulation.
Editorial
Loading solution…