Maximum Valid Substring Frequency
Problem statement
A valid substring of s is contiguous, has length from minLength through maxLength inclusive, and contains at most maxUnique distinct letters.
For this exercise, assume occurrences at different starting positions are counted separately, including overlapping occurrences. Return the largest occurrence count of any one valid substring value. Return 0 if no substring is valid. The result is a count, so no tie rule between equally frequent substring values is needed.
Function
maxSubstringFrequency(s: String, minLength: int, maxLength: int, maxUnique: int) → intExamples
Example 1
s = "aaaaa"minLength = 2maxLength = 3maxUnique = 1return = 4aa occurs at four starting positions, including overlaps. aaa occurs three times, so the answer is 4.
Example 2
s = "aabcabcaab"minLength = 3maxLength = 5maxUnique = 2return = 2aab occurs twice and uses only two distinct letters. It is a valid substring with the greatest frequency.
Example 3
s = "abc"minLength = 2maxLength = 2maxUnique = 1return = 0Both length-2 substrings contain two distinct letters and exceed the limit 1.
Constraints
1 <= s.length <= 10000;scontains lowercase English letters.1 <= minLength <= maxLength <= min(26, s.length).1 <= maxUnique <= 26.