AmazonOA #47
Analyze Product Code (Valid Substrings)
Estimated MediumJudge-ready
The string contains only a..g. Count the non-empty contiguous substrings in which the highest character frequency does not exceed the number of distinct characters.
Input
A single line containing a string over a..g, of length 1..100000.
Output
Output a single integer answer.
Example 1
Input:
abaa
Output:
8
Example 2
Input:
a
Output:
1
Example 3
Input:
abc
Output:
6
Example notes
Example 1: the four single characters, the two length-2 substrings ab and ba, and the two length-3 substrings aba and baa are valid, 8 in total; aa and abaa are not valid. Example 2: a single character has frequency 1 and 1 distinct character, so it is valid. Example 3: all six non-empty substrings are valid.
Editorial
Loading solution…