#C8041. Longest Substring with At Most Two Distinct Characters

    ID: 51980 Type: Default 1000ms 256MiB

Longest Substring with At Most Two Distinct Characters

Longest Substring with At Most Two Distinct Characters

Given a string s, find the length of the longest contiguous substring that contains at most two distinct characters.

For example, consider the string eceba. The longest substring that contains at most two distinct characters is ece with a length of 3.

The problem can be modeled using the sliding window technique. Formally, if you denote the input string as \(s\) of length \(n\), you need to determine the maximum \(L\) such that there exists some indices \(i\) and \(j\) with \(0 \le i \le j < n\) and the substring \(s[i\ldots j]\) contains at most two distinct characters.

\(\textbf{Input:}\) A non-empty string \(s\).
\(\textbf{Output:}\) An integer indicating the length of the longest substring of \(s\) that contains at most two distinct characters.

inputFormat

The input is read from standard input (stdin) and consists of a single line containing a non-empty string s composed of English letters.

outputFormat

The output should be written to standard output (stdout) as a single integer denoting the length of the longest substring that contains at most two distinct characters.

## sample
eceba
3