#49 Group Anagrams
Contents
Link
https://leetcode.com/problems/group-anagrams/description/
Solution
- Generating a custom key function is necessary.
- The custom key function in this case initializes a vector of 26 zeroes each represeting a letter in the alphabet.
- Each zero will be incremented by 1 giving us the count of letters in the given word.
- Time analysis:
- All the strings in the input array are going to be tranversed once.
O(N)
whereN
is the total number of strings in the input array. - If the max length of a string in the input array is
k
, the total time complexity of the given problem solution isO(Nk)
.
- All the strings in the input array are going to be tranversed once.
Code
C++
|
|
Notes
- Make sure to add 1 for each occurrence of letter in the word.