left
and right
, both set to 0.count
to keep track of the number of valid substrings.right
pointer over the string s
.
a. Increment the frequency of the character at the right
pointer.
b. While the frequency of the current character is greater than 1, decrement the frequency of the character at the left
pointer and increment left
.
c. If the window size (right - left + 1
) is equal to k
, increment count
.
d. If the window size is equal to k
, decrement the frequency of the character at the left
pointer and increment left
.count
.