Trains the technique from
LeetCode 1297Maximum Number of Occurrences of a SubstringThis is an original problem, written from a brief that listed the technique, the difficulty, the topics, the function shape and the input bounds — none of that problem's wording, examples, hints or editorials. The link is there so you can map your practice onto the standard set.
Same function shape, different story and different numbers.
A field controller writes one lowercase letter per tick into a status log, given as the string s. Analysts look for a signature: an unbroken stretch of the log that turns up again and again.
A stretch is only worth reporting when both of these hold:
maxLetters different letters;minSize and at most maxSize.A stretch occurs once for every starting position in s at which it appears, so two appearances that overlap are counted separately.
Return the largest number of occurrences achieved by any reportable stretch. If no stretch is reportable, return 0.
Example 1
The stretch "aa" uses one letter and has length 2, so it is reportable, and it starts at positions 0, 1, 4 and 5, which is four occurrences.
Example 2
The stretch "ef" uses two letters, which is the limit, and has length 2. It starts at positions 0, 2 and 4, so it occurs three times.
Example 3
Every stretch of length 3 or 4 in this log uses at least three different letters, which is above the limit of one, so nothing is reportable and the answer is 0.
The editor is preloaded with this. It matches the parent problem's shape, so a solution that works here transfers to a judge unchanged.
def max_freq(s: str, maxLetters: int, minSize: int, maxSize: int) -> int:public int maxFreq(String s, int maxLetters, int minSize, int maxSize)See the step-by-step animation, the intuition, and clean code in every language — free, no credit card.