1297. Maximum Number of Occurrences of a Substring Medium
1/**
2 * [1297] Maximum Number of Occurrences of a Substring
3 *
4 * Given a string s, return the maximum number of ocurrences of any substring under the following rules:
5 *
6 * The number of unique characters in the substring must be less than or equal to maxLetters.
7 * The substring size must be between minSize and maxSize inclusive.
8 *
9 *
10 * Example 1:
11 *
12 * Input: s = "aababcaab", maxLetters = 2, minSize = 3, maxSize = 4
13 * Output: 2
14 * Explanation: Substring "aab" has 2 ocurrences in the original string.
15 * It satisfies the conditions, 2 unique letters and size 3 (between minSize and maxSize).
16 *
17 * Example 2:
18 *
19 * Input: s = "aaaa", maxLetters = 1, minSize = 3, maxSize = 3
20 * Output: 2
21 * Explanation: Substring "aaa" occur 2 times in the string. It can overlap.
22 *
23 *
24 * Constraints:
25 *
26 * 1 <= s.length <= 10^5
27 * 1 <= maxLetters <= 26
28 * 1 <= minSize <= maxSize <= min(26, s.length)
29 * s consists of only lowercase English letters.
30 *
31 */
32pub struct Solution {}
33
34// problem: https://leetcode.com/problems/maximum-number-of-occurrences-of-a-substring/
35// discuss: https://leetcode.com/problems/maximum-number-of-occurrences-of-a-substring/discuss/?currentPage=1&orderBy=most_votes&query=
36
37// submission codes start here
38
39impl Solution {
40 pub fn max_freq(s: String, max_letters: i32, min_size: i32, max_size: i32) -> i32 {
41 0
42 }
43}
44
45// submission codes end
46
47#[cfg(test)]
48mod tests {
49 use super::*;
50
51 #[test]
52 fn test_1297() {
53 }
54}
55
Back
© 2025 bowen.ge All Rights Reserved.