#C8748. Count Anagram Groups
Count Anagram Groups
Count Anagram Groups
Given a list of strings, your task is to group the strings that are anagrams of each other and determine the number of distinct anagram groups.
Two words are anagrams if by rearranging the letters of one, you can obtain the other. For example, the words "eat", "tea", and "ate" are all anagrams of one another.
The input begins with an integer \( n \) representing the number of strings, followed by a line with \( n \) space-separated words. Mathematically, if we define a function \( sort(word) \) that sorts the letters of a word, then the set of anagram groups is given by:
\[ \text{groups} = \{ sort(word) \mid word \in \text{words} \} \]Your output should be the cardinality of this set, i.e. \( |\text{groups}| \).
Note: All words consist of lowercase English alphabets.
inputFormat
The first line contains an integer \( n \) \( (1 \leq n \leq 10^5) \), the number of words.
The second line contains \( n \) space-separated lowercase strings.
outputFormat
Output a single integer representing the number of distinct anagram groups.
## sample5
eat tea tan ate nat
2