Solvarch
DSA ProblemsProgressPlanRoadmapsReviewCheat SheetsCompaniesSystem DesignCS FundamentalsQuestion Bank
Theme
Problems

Group Anagrams

Medium
stringhash-tablesorting

Group the words that are anagrams of each other.

Input: one line of space-separated words. Output: one group per line, the words within a group in sorted order (groups themselves may be produced in any order — the template prints them canonically).

Example 1
Input:
eat tea tan ate nat bat
Output:
ate eat tea
bat
nat tan

Anagram groups: {eat,tea,ate}, {tan,nat}, {bat}.

Example 2
Input:
a
Output:
a

Constraints

  • 1 ≤ words ≤ 10^4
  • 0 ≤ word length ≤ 100; lowercase letters.
Watch a video walkthrough

Run your code against the sample tests, or Submit to run the full suite.