Dsa
Sorting
Easy
Color Frequency Sorter
You are given a list of colors represented by their names. Your task is to sort the colors based on their frequency in descending order. If two colors have the same frequency, sort them alphabetically.
Input format:
- The first line contains a single integer, n (1 ≤ n ≤ 1000): the number of colors.
- The next n lines contain a string, each representing a color name.
Output format:
- Print the sorted list of colors according to the specified criteria, each on a new line.
Example:
Input:
5
red
blue
green
red
yellow
Output:
red
blue
green
yellow
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