#C3989. Longest Substring with Two Distinct Characters
Longest Substring with Two Distinct Characters
Longest Substring with Two Distinct Characters
Given a string s
, find the length of the longest contiguous substring that contains exactly two distinct characters.
If the string contains fewer than two distinct characters, the answer is simply the length of the string.
For example, for s = "eceba"
, the longest substring with exactly two distinct characters is "ece" with length 3.
The constraints can be summarized as: \(0 \leq |s| \leq 10^5\).
inputFormat
The input consists of a single line containing the string s
. The string may contain any characters.
Note: For the purpose of this problem, the entire input string is taken from the first line of the standard input.
outputFormat
Output a single integer representing the length of the longest substring of s
that contains exactly two distinct characters.
eceba
3