JavaScript, Most common technique with good explanation
Time complexity is 95.53%\n\nYou can follow along with my numbered markers which are pointers to comments in the code block\n\n1. Just general validations & che
**Time complexity is 95.53%**\n\n**You can follow along with my numbered markers which are pointers to comments in the code block**\n\n1. Just general validations & checks\n2. Using `Map()` because most of the operations I\'ll be using are `O(1)`, you could opt for a dictionary using an object but you\'ll see in step 5 we optimize for speed\n3. We loop over every word\n4. We create 2 variables, 1 is the word, 1 is the word but sorted alphabetically\n\t- worst `O(n^2)`\n\t- avg `O(n log(n))`\n5. The magic of our `Map()` is here\n\t- If our sorted word matches any existing sorted word (which makes it an anagram) then we add it to our anagram list\n\t- If our sorted word doesn\'t match anything, add a new entry to the map\n\t\t- The key would be the sorted word\n\t\t- The value would be an array of the word eg. `["word"]`\n\t- `Map().size` is an `O(1)` solution of getting the length vs `Object.entries(...).length` is an `O(n)` because of converting an object to an array\n\t- `get()`, `has()`, `push()` and `set()` are all `O(1)`\n\t- The only added benefit of using this over a dictionary is readability and the `size` prototype from `Map()`\n6. We\'ll have all our results stored in our `Map()`, we just iterate over all our results and put them into 1 array then return that!\n\n```\n// 1\nif (strs.length === 0) return []\nif (strs.length === 1) return [strs]\n\n// 2\nconst words = new Map()\n\n// 3\nfor (let i = 0; i < strs.length; i++) {\n\tconst word = strs[i]\n\tconst wordSorted = [...word].sort().join(\'\') // 4\n\n\t// 5\n\tif (words.size > 0 && words.has(wordSorted)) {\n\t\twords.get(wordSorted).push(word)\n\t} else {\n\t\twords.set(wordSorted, [word])\n\t}\n}\n\n// 6\nconst result = []\n\nfor (const [_, list] of words.entries()) {\n\tresult.push(list)\n}\n\nreturn result\n```\n\nHope you guys enjoyed this!
['JavaScript']