Intermediate Level
Implement the groupAnagramCount method that counts how many anagram groups are formed from the words.
The input contains an array of strings words and its length size. Your task is to group words that are anagrams of each other and return the number of groups formed.
For example, [eat,tea,tan,ate,nat,bat] forms three groups: [eat,tea,ate], [tan,nat], and [bat], so the answer is 3.
All anagrams have the same characters after sorting their letters.
For each word, sort its characters to create a common key. Store that key in a set or map. Words with the same sorted key belong to the same anagram group.
After processing all words, the number of unique keys is the number of anagram groups.
Pseudocode:
function groupAnagramCount(words, size):
groups = empty set
for i from 0 to size - 1:
key = characters of words[i] sorted in ascending order
add key to groups
return size of groups