anagrams:

Group Anagrams

Given an array of strings, group anagrams together. Example Input: ["eat", "tea", "tan", "ate", "nat", "bat"], Output: [ ["ate","eat","tea"], ["nat","tan"], ["bat"] ] Note All inputs will be in lowercase. The order of your output does not matter. Solution (naive) Time: O(Nklogk), k: length of the longest word Space: O(Nk) sort each word and use it the sorted str as a key to the lookup dictionary class Solution: def groupAnagrams(self, strs: List[str]) -> List[List[str]]: ans = collections.

by lek tin in "algorithm" access_time 2-min read