#K71412. Longest Substring with At Most Two Distinct Characters
Longest Substring with At Most Two Distinct Characters
Longest Substring with At Most Two Distinct Characters
Given a string \( s \), your task is to find the length of the longest substring that contains at most two distinct characters. This problem requires you to compute the maximum length of any contiguous segment in \( s \) that has no more than two unique characters.
For example, when \( s = \text{'eceba'} \), the longest such substring is \( \text{'ece'} \), which has a length of \( 3 \). Similarly, for input \( s = \text{'ccaabbb'} \), the longest substring meeting the condition is \( \text{'aabbb'} \) (or \( \text{'ccaab'} \)) with a length of \( 5 \).
Note that if the input string is empty, the output should be \( 0 \). The string \( s \) consists only of English letters.
inputFormat
The input is provided as a single line from stdin which contains the string \( s \). Note that this string can be empty.
outputFormat
Output a single integer to stdout that represents the length of the longest substring containing at most two distinct characters.
## samplea
1