Group Words by Letters
You are given a list of lowercase words. Two words belong together when one can be spelled by rearranging the letters of the other: "stop" and "pots" do, "stop" and "cat" do not.
Return the words in groups, one group per set of letters. The groups can come in any order, and so can the words inside each group. A word that appears twice appears twice in its group.
Examples
["stop", "pots", "tops", "cat", "act", "dog"]
→ [["stop", "pots", "tops"], ["cat", "act"], ["dog"]]
["x"] → [["x"]]Constraints
- Between 1 and 5,000 words, each at most 20 letters from
atoz. - Aim for a solution that handles each word once: O(n) in the number of words (each word's length is small and bounded).
Console
›Run to see what your code prints
Run checks the 3 visible cases here, in your browser. Submit runs all 6 on the judge, 3 of them hidden, and measures how your solution scales.
Expected is the reference solution's answer, from the judge. An input that breaks the statement's other rules may get any answer.