#C1700. Longest Substring with K Distinct Characters

    ID: 44935 Type: Default 1000ms 256MiB

Longest Substring with K Distinct Characters

Longest Substring with K Distinct Characters

Given a string \(s\) and an integer \(k\), find the length of the longest contiguous substring that contains at most \(k\) distinct characters. This problem is a classic example of the sliding window technique.

Input: A string of lowercase English letters and an integer \(k\).

Output: A single integer denoting the length of the longest substring of \(s\) with at most \(k\) distinct characters.

inputFormat

The input is read from standard input (stdin). It consists of two lines: the first line contains the string \(s\) (only lowercase English letters), and the second line contains the integer \(k\).

outputFormat

The output is a single integer written to standard output (stdout): the length of the longest substring of \(s\) that contains at most \(k\) distinct characters.

## sample
eceba
2
3