SnowflakeOA #35
Max Frequency Substring
Estimated MediumJudge-ready
Topics (AI-labelled)HashingTwo Pointers
Among contiguous substrings with length in [minLength,maxLength] and a number of distinct characters ≤maxUnique, find the maximum number of occurrences of the same text; overlapping occurrences are allowed. Return 0 if no substring qualifies.
Input
This site's JSON input: [s,minLength,maxLength,maxUnique], which may contain escaped whitespace or Unicode; lengths are counted in Unicode characters. This site uses 1≤|s|≤100000, 1≤minLength≤maxLength≤|s|, and 1≤maxUnique≤100000.
Output
Output the single integer required by the problem.
Example 1
Input:
["aaaa", 2, 3, 1]
Output:
3
Example 2
Input:
["aabcaab", 2, 4, 2]
Output:
2
Example 3
Input:
["a b a b", 3, 5, 3]
Output:
2
Example notes
The answers to the three public examples are, in order: 3; 2; 2. The examples were rechecked by independent enumeration, state search, or direct simulation.
Editorial
Loading solution…