#C10520. Maximum Anagram Group
Maximum Anagram Group
Maximum Anagram Group
Given a list of n strings, an anagram group is defined as a set of strings that become identical when their characters are rearranged in sorted order. Your task is to compute the size of the largest anagram group. In other words, determine the maximum number of strings in the input that are all anagrams of each other.
The input is read from stdin
and the result must be printed to stdout
. Efficient processing is recommended, as individual strings can be very long. Formally, if for a string s we denote by sorted(s) its characters sorted in non-decreasing order, then we wish to compute
\[
\max_{G}\;|G|,
\]
where the maximum is taken over all groups G of strings that satisfy sorted(s1) = sorted(s2)
for all s1, s2 in G.
inputFormat
The input is given via stdin
and has the following format:
- The first line contains an integer n — the number of strings.
- Each of the next n lines contains a single non-empty string consisting of lowercase English letters.
In concise notation: The first line contains an integer $n$. Then $n$ lines follow, each containing a string $s_i$.
outputFormat
Output a single integer — the maximum number of anagrams that can be formed from the given list of strings. This value corresponds to the size of the largest group of strings that are anagrams of each other.
## sample6
listen
silent
enlist
google
elgoog
notanagram
3
</p>