303. At Most K Different Characters
Print the length of the longest contiguous stretch of the string containing
at most k distinct characters.
eceba, k = 2 -> 3 (ece)
Slide a window and keep a map from character to how many times it occurs INSIDE
the window. Grow on the right; while the map holds more than k distinct
characters, shrink from the left.
The detail that decides correctness is removing a key when its count reaches zero. The number of distinct characters is the map's SIZE, and a key left behind with a count of zero keeps inflating it, so the window shrinks further than it should and the answer comes out too small.
Constraints - `1 ≤ k ≤ 26` - `1 ≤ length ≤ 200000` - The string contains lowercase letters only.
Input
The first line contains an integer k.
The second line contains a string of lowercase letters.
Output
Print one integer, the length of the longest stretch with at most k distinct characters.
Hints
Four rungs, in order. The last two open once you have submitted an attempt. A wrong one counts.