1297. Maximum Number of Occurrences of a Substring
1297. Maximum Number of Occurrences of a Substring
Description
Given a string s, return the maximum number of occurrences of any substring under the following rules:
- The number of unique characters in the substring must be less than or equal to
maxLetters. - The substring size must be between
minSizeandmaxSizeinclusive.
Example 1:
1 | Input: s = "aababcaab", maxLetters = 2, minSize = 3, maxSize = 4 |
Example 2:
1 | Input: s = "aaaa", maxLetters = 1, minSize = 3, maxSize = 3 |
Constraints:
1 <= s.length <= 10^51 <= maxLetters <= 261 <= minSize <= maxSize <= min(26, s.length)sconsists of only lowercase English letters.
Hints/Notes
- 2024/10/16
- sliding window
- because every larger subString must contains smaller subString, we should only care about the subStrings with minSize
- can use string_view but there’s no need
- No solution from 0x3F
Solution
Language: C++
1 | class Solution { |