Tap here to switch tabs
Problem
Submissions

Problem: Maximum Number of Occurrences of a Substring

med
30 min
Try to solve the Maximum Number of Occurrences of a Substring problem.

Statement

Given a string s and integers maxLetters, minSize, and maxSize, consider all substrings of s whose length is between minSize and maxSize inclusive. A substring is valid if it contains at most maxLetters distinct characters.

Return the maximum number of times any valid substring occurs in s.

Note: Occurrences of a substring may overlap.

Constraints:

  • 1≤1 \leq s.length ≤105\leq 10^5

  • 1≤1 \leq maxLetters ≤26\leq 26

  • 1≤1 \leq minSize ≤\leq maxSize ≤min⁡(26,ext‘s.length‘)\leq \min(26,\\ ext{`s.length`})

  • s consists of only lowercase English letters.

⋮
Tap here to switch tabs
Problem
Submissions

Problem: Maximum Number of Occurrences of a Substring

med
30 min
Try to solve the Maximum Number of Occurrences of a Substring problem.

Statement

Given a string s and integers maxLetters, minSize, and maxSize, consider all substrings of s whose length is between minSize and maxSize inclusive. A substring is valid if it contains at most maxLetters distinct characters.

Return the maximum number of times any valid substring occurs in s.

Note: Occurrences of a substring may overlap.

Constraints:

  • 1≤1 \leq s.length ≤105\leq 10^5

  • 1≤1 \leq maxLetters ≤26\leq 26

  • 1≤1 \leq minSize ≤\leq maxSize ≤min⁡(26,ext‘s.length‘)\leq \min(26,\\ ext{`s.length`})

  • s consists of only lowercase English letters.