IBMOA #29
Get Max Occurrences
Estimated MediumJudge-ready
Topics (AI-labelled)HashingTwo Pointers
Find the maximum number of times a substring occurs in the original string; occurrences may overlap. Candidate lengths are between minLength and maxLength, and the number of distinct characters must not exceed maxUnique; output 0 if there is no valid candidate.
Input
The first line contains minLength maxLength maxUnique, and the second line contains the string. Original bounds: 2≤length≤100000, 2≤minLength≤maxLength≤26 and maxLength<string length, 2≤maxUnique≤26. The source does not restrict the character set; this site supports non-newline Unicode scalar characters, each character counts as one code point, and the total UTF-8 size is ≤400100 bytes.
Output
Output one integer, the answer.
Example 1
Input:
2 4 2
abcde
Output:
1
Example 2
Input:
2 3 2
ababab
Output:
3
Example 3
Input:
2 3 2
aaaa
Output:
3
Example notes
The examples give 1, 3 and 3 respectively; ab occurs 3 times in ababab, and occurrences of aa may overlap.
Editorial
Loading solution…