You are given a string word and an integer k.
A substring s of word is complete if:
Return the number of complete substrings of word.
A substring is a non-empty contiguous sequence of characters in a string.
Examples
Example 1
Input: word = "igigee", k = 2
Output: 3
Explanation: The complete substrings where each character appears exactly twice and the difference between adjacent characters is at most 2 are: igigee, igigee, igigee.
Example 2
Input: word = "aaabbbccc", k = 3
Output: 6
Explanation: The complete substrings where each character appears exactly three times and the difference between adjacent characters is at most 2 are: aaabbbccc, aaabbbccc, aaabbbccc, aaabbbccc, aaabbbccc, aaabbbccc.
Constraints
1 <= word.length <= 105
word consists only of lowercase English letters.
1 <= k <= word.length
2953. Count Complete Substrings
Hard
50 Points
Hash Table
String
Sliding Window
You are given a string word and an integer k.
A substring s of word is complete if:
Return the number of complete substrings of word.
A substring is a non-empty contiguous sequence of characters in a string.
Examples
Example 1
Input: word = "igigee", k = 2
Output: 3
Explanation: The complete substrings where each character appears exactly twice and the difference between adjacent characters is at most 2 are: igigee, igigee, igigee.
Example 2
Input: word = "aaabbbccc", k = 3
Output: 6
Explanation: The complete substrings where each character appears exactly three times and the difference between adjacent characters is at most 2 are: aaabbbccc, aaabbbccc, aaabbbccc, aaabbbccc, aaabbbccc, aaabbbccc.
Constraints
1 <= word.length <= 105
word consists only of lowercase English letters.
1 <= k <= word.length
Count Complete Substrings - Practice Coding | SlaveCode