Find the largest group of anagram words

Write codeMedium20 min

Your task

A word puzzle app groups words that are anagrams of each other, so players can see which words share the same letters. The editors want to know how big the biggest group is.

Write largest_anagram_group(words) that returns the number of words in the largest group.

Input and output:

  • words: a list of up to 10,000 words. Each word has 1 to 100 lowercase letters a to z. The list may be empty.
  • Returns an integer.

Rules:

  • Words are anagrams of each other when they use the same letters the same number of times, in any order.
  • A group is a word together with every other word in the list that is an anagram of it.
  • The same word can appear more than once, and each copy counts as a separate member of its group.
  • An empty list returns 0.

Examples

largest_anagram_group(words: list[str]) -> int
Example 1
Inputlargest_anagram_group(["listen", "silent", "enlist", "hello"])
Output3
Example 2
Inputlargest_anagram_group(["dusty", "study", "night", "thing", "study"])
Output3
Example 3
Inputlargest_anagram_group(["aab", "aba", "abb"])
Output2