Class Solution
java.lang.Object
g2901_3000.s2953_count_complete_substrings.Solution
public class Solution
extends java.lang.Object
2953 - Count Complete Substrings.
Hard
You are given a string word
and an integer k
.
A substring s
of word
is complete if:
- Each character in
s
occurs exactlyk
times. - The difference between two adjacent characters is at most
2
. That is, for any two adjacent charactersc1
andc2
ins
, the absolute difference in their positions in the alphabet is at most2
.
Return the number of complete substrings of word
.
A substring is a non-empty contiguous sequence of characters in a string.
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: igig ee, igig ee , 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: **aaa**bbbccc, aaa bbb ccc, aaabbb ccc , **aaabbb**ccc, aaa bbbccc , aaabbbccc .
Constraints:
1 <= word.length <= 105
word
consists only of lowercase English letters.1 <= k <= word.length
-
Constructor Summary
Constructors -
Method Summary
Methods inherited from class java.lang.Object
clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
-
Constructor Details
-
Solution
public Solution()
-
-
Method Details
-
countCompleteSubstrings
public int countCompleteSubstrings(java.lang.String word, int k)
-