#K93647. 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, find the length of the longest substring that contains at most two distinct characters.
For example, if s = "eceba", the longest substring is "ece" with length 3; if s = "ccaabbb", the longest substring is "aabbb" with length 5.
This problem can be solved efficiently using the sliding window technique. If a formula is needed, one might express the constraint as follows: \( |{c \in \text{substring}}| \leq 2 \).
inputFormat
The input consists of a single line containing the string s. The string may consist of lowercase letters. Read the input from stdin.
outputFormat
Output a single integer representing the length of the longest substring of s that contains at most two distinct characters. Write the result to stdout.
## sampleeceba
3