k
of each character. If not, return -1.left
and right
.left
to 0 and right
to the length of the string minus 1.left
is less than or equal to right
, do the following:
a. Check if the current window is valid (i.e., outside the window, there are at least k
of each character).
b. If valid, update the result with the current window size and move the left
pointer to the right (shrink the window from the left).
c. If not valid, move the right
pointer to the left (shrink the window from the right).