#2953
Count Complete Substrings
international master · 1990 · lc hard +32 · verified · 30% accepted · 258 likes · top 7%
Description
You are given a string word and integer k. A substring is complete when every character in it appears exactly k times and every pair of adjacent characters are at most 2 positions apart in the alphabet.
Return the total count of complete substrings in word.
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.
Code
1
2
3