416. Longest Substring With K Distinct Characters
MediumSliding Window
Print the length of the longest substring with at most k distinct characters.
Input format
Line 1: s Line 2: k
Output format
The length.
Example 1
Input
eceba 2
Output
3
Example 2
Input
aa 1
Output
2
Constraints
1 ≤ |s| ≤ 10⁵ 0 ≤ k ≤ 26
Read input from standard input and print the answer to standard output. Your code is judged against 5 test cases, most of them hidden.
Loading the MyLoginn IDE…