#C14302. Longest Substring with At Most Two Distinct Characters

    ID: 43937 Type: Default 1000ms 256MiB

Longest Substring with At Most Two Distinct Characters

Longest Substring with At Most Two Distinct Characters

Given a string \( s \), your task is to determine the length of the longest contiguous substring that contains at most two distinct characters. In other words, you need to find the maximum \( \text{length} \) of a substring in which the number of unique characters is less than or equal to 2.

For example, if \( s = \texttt{eceba} \), the longest substring with at most two distinct characters is \( \texttt{ece} \) with a length of \( 3 \). Similarly, if \( s = \texttt{ccaabbb} \), the longest valid substring is \( \texttt{aabbb} \) with a length of \( 5 \).

Your solution should be efficient with respect to time complexity.

inputFormat

The input consists of a single line containing the string \( s \). The string may consist of alphabets and other printable characters.

outputFormat

Output a single integer representing the length of the longest substring of \( s \) that contains at most two distinct characters.

## sample
eceba
3