Implement a function that takes an array of strings strs
and returns a list of groups, where each group contains strings that are anagrams of one another. The groups can be returned in any order.
Two strings are considered anagrams if they use exactly the same letters with the same frequency, just arranged differently. For example, "listen" and "silent" are anagrams since they contain the same letters.
Constraints:
strs.length
≤ 1000strs[i].length
≤ 100strs[i]
consists of lowercase English letters.Examples:
// Example 1 const strs1 = ["act","pots","tops","cat","stop","hat"]; console.log(groupAnagrams(strs1)); // Output: [["hat"],["act", "cat"],["stop", "pots", "tops"]] // Example 2 const strs2 = ["x"]; console.log(groupAnagrams(strs2)); // Output: [["x"]] // Example 3 const strs3 = [""]; console.log(groupAnagrams(strs3)); // Output: [[""]]