Dsa
Sorting
Medium
Anagram Density Sort
Given a list of words, sort them based on the 'density' of their anagram group. Specifically, sort by the total number of times any anagram of that word appears in the input list (descending). If densities are equal, sort by the alphabetically sorted version of the word (ascending). If still tied, sort by the original word (ascending).
Example:
Input: 'cat dog act tac god'
- 'cat', 'act', 'tac' are anagrams. Group size: 3.
- 'dog', 'god' are anagrams. Group size: 2.
Output:
act
cat
tac
dog
god
Key concepts
sortingfrequency-analysisanagrams
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