LeetCode
Longest Substring with At Most K Distinct Characters
Click
here
for an explanation.