## Video

https://youtu.be/7KHKFqLPMbs

## Problem and Constraints

Given a set of strings. Return anagrams in group.

## All Approaches and Explanations in English

### O(n) time complexity. O(n) space complexity

O(N*26) time complexity.

compare the count of letters in each word and put group them in a map

## Works but okay, okay

class Solution {

private String getLetterCount(String str){
int[] count = new int[26];

for(char c: str.toCharArray()){
count[c-'a']++;
}
return Arrays.toString(count);
}

public List<List<String>> groupAnagrams(String[] strs) {
Map<String, List<String>> groups = new HashMap<>();
for(String str: strs){
String letterCount = getLetterCount(str);
List<String> list = groups.getOrDefault(letterCount, new ArrayList<>());
groups.put(letterCount, list);
}

return new ArrayList<>(groups.values());
}
}


Optimizations: rather than: Arrays.toString(count); could have been: new String(count)

rather than:

            List<String> list = groups.getOrDefault(letterCount, new ArrayList<>());

letterCount could be renamed as hash. #DDD

groups.computeIfAbsent(letterCount, k-> new ArrayList<>())