2953. Count Complete Substrings Hard

@problem@discussion
#Hash Table#String#Sliding Window



1/**
2 * [2953] Count Complete Substrings
3 *
4 * You are given a string word and an integer k.
5 * A substring s of word is complete if:
6 * 
7 * 	Each character in s occurs exactly k times.
8 * 	The difference between two adjacent characters is at most 2. That is, for any two adjacent characters c1 and c2 in s, the absolute difference in their positions in the alphabet is at most 2.
9 * 
10 * Return the number of complete substrings of word.
11 * A substring is a non-empty contiguous sequence of characters in a string.
12 *  
13 * <strong class="example">Example 1:
14 * 
15 * Input: word = "igigee", k = 2
16 * Output: 3
17 * Explanation: The complete substrings where each character appears exactly twice and the difference between adjacent characters is at most 2 are: <u>igig</u>ee, igig<u>ee</u>, <u>igigee</u>.
18 * 
19 * <strong class="example">Example 2:
20 * 
21 * Input: word = "aaabbbccc", k = 3
22 * Output: 6
23 * Explanation: The complete substrings where each character appears exactly three times and the difference between adjacent characters is at most 2 are: <u>aaa</u>bbbccc, aaa<u>bbb</u>ccc, aaabbb<u>ccc</u>, <u>aaabbb</u>ccc, aaa<u>bbbccc</u>, <u>aaabbbccc</u>.
24 * 
25 *  
26 * Constraints:
27 * 
28 * 	1 <= word.length <= 10^5
29 * 	word consists only of lowercase English letters.
30 * 	1 <= k <= word.length
31 * 
32 */
33pub struct Solution {}
34
35// problem: https://leetcode.com/problems/count-complete-substrings/
36// discuss: https://leetcode.com/problems/count-complete-substrings/discuss/?currentPage=1&orderBy=most_votes&query=
37
38// submission codes start here
39
40impl Solution {
41    pub fn count_complete_substrings(word: String, k: i32) -> i32 {
42        0
43    }
44}
45
46// submission codes end
47
48#[cfg(test)]
49mod tests {
50    use super::*;
51
52    #[test]
53    fn test_2953() {
54    }
55}
56


Back
© 2025 bowen.ge All Rights Reserved.