#K44302. 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.
For example:
- For
s = "eceba"
, the longest valid substring is "ece" which has a length of 3. - For
s = "ccaabbb"
, the longest valid substring is "aabbb" which has a length of 5.
You are required to read the input from stdin and write the result to stdout.
Note: The input string can be empty. In that case, the output should be 0
.
inputFormat
The input consists of a single line containing the string s
. The string may be empty and will contain only ASCII characters.
outputFormat
Output a single integer representing the length of the longest substring of s
that contains at most two distinct characters.## sample
0