Count → bucket by frequency (or heap). Interview favorite: bucket sort O(n).
Input
6 2 1 1 1 2 2 3
Output
1 2
1 1 1
1