30:00
Given a string s and an integer k, return the length of the longest substring of s that contains at most k distinct characters.
1≤s.length≤5×1041 \leq s.\text{length} \leq 5 \times 10^41≤s.length≤5×104
0≤k≤500 \leq k \leq 500≤k≤50
Find longest substring with at most 2 distinct characters
e
0
c
1
2
b
3
a
4
left=0
right=-1
Character Count Map (k=2)
empty
distinct = 0 ≤ k = 2
Window Length:
Max Length:
Pointers
Valid Window
Invalid Window