AmazonOA #119
Count Dominant Substrings
Estimated MediumJudge-ready
Topics (AI-labelled)HashingPrefix & RangesStrings
Count even-length substrings by index: a substring counts once if at least one character occurs exactly half its length times. If two characters each make up half, it still counts only once.
Input
One line with a string. This site sets the length to 1..100000 with lowercase letters only.
Output
Output a single integer answer.
Example 1
Input:
aaaaid
Output:
3
Example 2
Input:
abab
Output:
4
Example 3
Input:
aa
Output:
0
Example notes
Example 1: the valid ones are ai, id and aaid, 3 in total; the aa in the source explanation does not satisfy the definition. Example 2: the three substrings of length 2 plus the whole abab, 4 in total. Example 3: in aa, a occurs 2 times rather than half the length, 1, so the answer is 0.
Editorial
Loading solution…