#C13370. Longest Substring with At Most K Distinct Characters
Longest Substring with At Most K Distinct Characters
Longest Substring with At Most K Distinct Characters
Given a string (s) and an integer (k), your task is to compute the length of the longest substring that contains at most (k) distinct characters.
This problem can be solved with the sliding window technique. For a substring defined by indices (l) and (r), we must guarantee that the number of unique characters in (s[l \dots r]) does not exceed (k).
inputFormat
The input consists of two lines:
1. The first line is the string (s).
2. The second line is an integer (k), representing the maximum number of distinct characters allowed in the substring.
outputFormat
Output a single integer: the length of the longest substring of (s) that contains at most (k) distinct characters.## sample
eceba
2
3