Skip to content

Practice Maximum Number of Occurrences of a Substring

Read the task, work through the examples, and check your approach against the constraints. Use the original LeetCode task for coding and submissions.

Medium#1297
LeetCode Problem

Maximum Number of Occurrences of a Substring

Problem Statement

Among substrings of s whose length lies from minSize through maxSize inclusive and which contain at most maxLetters distinct characters, return the largest occurrence count of any one substring. Occurrences at different starting positions count separately, including overlaps.

Source: Maximum Number of Occurrences of a Substring on LeetCode. Use the original task for its coding environment and submissions.

Examples

# Example 1

Input
s = "aababcaab", maxLetters = 2, minSize = 3, maxSize = 4
Output
2

# Example 2

Input
s = "aaaa", maxLetters = 1, minSize = 3, maxSize = 3
Output
2

Constraints

1 <= s.length <= 10^5
1 <= maxLetters <= 26
1 <= minSize <= maxSize <= min(26, s.length)
s consists of only lowercase English letters.

Related LeetCode Problems

Practice more problems similar to Maximum Number of Occurrences of a Substring.

Review your practice with PhantomCodeAI

After trying the problem yourself, use the app to discuss your approach, complexity, and edge cases.