Longest Substring with At Most K Distinct — sliding window
Grow the right edge each step; when the window holds too many distinct characters, slide the left edge once. The window never shrinks.
Try:
distinct = 0 / k
window size = 0
character counts in the window