Practice/Amazon/Leetcode 49. Group Anagrams
CodingMust
Given an array of strings, organize them into clusters where each cluster contains words that have identical letter compositions. Two words belong to the same cluster if they contain exactly the same letters with the same frequencies, regardless of order.
Return the clusters in any order. The words within each cluster can also appear in any order.
0 <= words.length <= 100000 <= words[i].length <= 100words[i] consists of lowercase English letters onlyO(n * k) where n is the number of words and k is the maximum length of a wordO(n * k) for storing the results and intermediate data structuresExample 1:
` Input: words = ["eat", "tea", "tan", "ate", "nat", "bat"] Output: [["eat", "tea", "ate"], ["tan", "nat"], ["bat"]] Explanation:
Example 2:
Input: words = [""] Output: [[""]] Explanation: An empty string forms its own cluster
Example 3:
Input: words = ["a"] Output: [["a"]] Explanation: A single word forms a single cluster
Example 4:
Input: words = ["listen", "silent", "enlist"] Output: [["listen", "silent", "enlist"]] Explanation: All three words contain the same letters with identical frequencies