diff --git a/src/my_project/interviews/google_top_exercises/round_1/11_group_anagrams.py b/src/my_project/interviews/google_top_exercises/round_1/11_group_anagrams.py new file mode 100644 index 00000000..fad0a4d3 --- /dev/null +++ b/src/my_project/interviews/google_top_exercises/round_1/11_group_anagrams.py @@ -0,0 +1,12 @@ +from collections import defaultdict +from typing import List + +class Solution: + def groupAnagrams(self, strs: List[str]) -> List[List[str]]: + + answer = defaultdict(list) + + for word in strs: + answer[''.join(sorted(word))].append(word) + + return list(answer.values()) \ No newline at end of file