#K93977. Longest Substring with Two Distinct Characters After One Removal
Longest Substring with Two Distinct Characters After One Removal
Longest Substring with Two Distinct Characters After One Removal
You are given a string s consisting of lowercase English letters. You must remove exactly one character from s and then find the length of the longest contiguous substring that contains at most two distinct characters. The removal operation is mandatory even if the string already satisfies the condition.
For example, if s = "eceba" then by removing the character at an appropriate position, the longest valid substring is "ece" whose length is 3. Similarly, if s = "ccaabbb", the answer is 5.
Note that if after removal the string becomes empty, the answer is 0.
The task is to compute the maximum possible length of a substring which, after removing exactly one character from the original string, contains at most two distinct characters. Any formulas such as the length of a substring n can be denoted in LaTeX format, e.g. $n$, if necessary.
inputFormat
The input is provided via stdin as a single line containing the string s.
outputFormat
Output a single integer through stdout representing the maximum length of a contiguous substring that contains at most two distinct characters after removing exactly one character from the original string.
## sampleeceba
3