Loading problem...
You are given an array of strings. Your task is to organize these strings into clusters where each cluster contains strings that are anagrams of each other.
Two strings are considered anagrams if one string can be formed by rearranging the characters of the other string. In other words, they contain exactly the same characters with the same frequencies, just in a potentially different order.
Return a list of clusters, where each cluster is a list of strings that are anagrams of one another. The ordering of clusters in the result does not matter, and the ordering of strings within each cluster also does not matter.
strs = ["eat","tea","tan","ate","nat","bat"][["bat"],["nat","tan"],["ate","eat","tea"]]The strings "eat", "tea", and "ate" are anagrams of each other (all contain letters 'a', 'e', 't'). The strings "tan" and "nat" are anagrams (both contain letters 'a', 'n', 't'). The string "bat" has no anagram partner in the list (only string with letters 'a', 'b', 't'), so it forms its own cluster.
strs = [""][[""]]There is only one empty string, which forms its own cluster. An empty string is only an anagram of itself.
strs = ["a"][["a"]]A single-character string can only be an anagram of itself. Since there's only one such string, it forms a cluster of one element.
Constraints