AmazonOA #144
Find Dominance
Estimated MediumJudge-ready
Topics (AI-labelled)Trie & CodecHashing
n strings all have length m. For each length 1..m, find how many times the most frequent prefix occurs; duplicate strings are counted as separate input records, and only the count is output, not the prefix.
Input
The first line contains n m, followed by n strings of equal length. The source has 2≤n≤500 and 1≤m≤2000; the source does not restrict the character set, and this site uses lowercase letters.
Output
Output m maximum occurrence counts for prefix lengths 1..m in order.
Example 1
Input:
3 3
aba
abb
aba
Output:
3 3 2
Example 2
Input:
3 3
abc
aaa
aba
Output:
3 2 1
Example 3
Input:
2 2
aa
aa
Output:
2 2
Example notes
Example 1: a and ab each occur 3 times, and aba occurs 2 times, so output 3 3 2. Example 2: the first letter a occurs 3 times, ab 2 times, and each full string once, so output 3 2 1. Example 3: the prefixes of both lengths occur 2 times, so output 2 2.
Editorial
Loading solution…