#K79892. 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 ) of length ( n ), find the length of the longest substring that contains at most 2 distinct characters.
In other words, you need to determine the maximum ( L ) such that there exists a substring of ( s ) of length ( L ) which contains no more than 2 different characters.
For example, if ( s = \texttt{eceba} ), the longest substring is ( \texttt{ece} ) with length 3.
inputFormat
The input consists of a single line containing the string ( s ). The string may be empty and will only consist of printable characters.
outputFormat
Output a single integer which is the length of the longest substring of ( s ) that contains at most two distinct characters.## sample
eceba
3