N
is smaller than 3
, return N
.left = 0
and right = 0
and max_len = 2
.right
pointer over the string:
3
distinct characters, add the current character s[right]
to the hashmap and move right
pointer to the right.3
distinct characters, remove the leftmost character from the hashmap and move the left
pointer to exclude this character from the window.max_len
with the maximum of its current value and the length of the current window.max_len
as the result.