Dsa
Sorting
Easy
Frequent Number Sort
You are given a list of integers. Your task is to sort the list based on the frequency of each number in descending order. If two numbers have the same frequency, sort them in ascending order. Output the sorted list as a single line of integers.
Example:
Input:
9 3 9 1 3 2 1 2 2
Output:
2 2 3 3 1 1 9 9
Key concepts
sortingfrequencycounting
Practise this out loud — free
Start a mock interview on THIS exact question — a voice AI interviewer opens with it, pushes back like a real onsite, then hands you an instant scorecard.
🎙 Practise this question now