#K61457. 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.
The substring must be contiguous. For example, when s = "eceba"
, the longest substring with at most two distinct characters is ece
, so the answer is 3
.
Note: If the input string is empty, the answer is 0
.
Input and Output Format: The program reads the input from standard input (stdin) and prints the result to standard output (stdout).
inputFormat
A single line containing the string s
.
outputFormat
An integer representing the length of the longest substring of s
that contains at most two distinct characters.## sample
eceba
3