The Anagram Archive
HardAcc. 72.1%
+50 XP 25
The Anagram Archive
In the world of linguistics, Anagrams are words that share the exact same characters but in a different order (like "listen" and "silent"). Your mission is to build a categorization engine that groups all anagrams together from a massive list of strings. To do this efficiently, we create a "Linguistic Signature" for each word by sorting its letters.
The Assignment
Your mission is to group the anagrams. Your function receives an array of strings strs.
- Create a Map or Object where each key is a "Linguistic Signature" (a sorted version of a word).
- For each word in the input list:
- Generate its signature by sorting its characters:
s.split('').sort().join(''). - Add the original word to the group matching that signature in your map.
- Generate its signature by sorting its characters:
- Print each group of anagrams on a separate line, with words in each group separated by spaces.
01EXAMPLE 1
Input
["eat", "tea", "tan", "ate", "nat", "bat"]Output
eat tea ate
tan nat
batExplanation: Groups categorized by letters.
Constraints
- Maintain stable grouping order.
ArraysHashingStrings
JavaScriptSystem handles I/O — write your function only
Loading...
1 Hidden
Input Arguments
strs["eat","tea","tan","ate","nat","bat"]
Expected Output
eat tea ate tan nat bat
Click RUN to test your solution