#C14513. Longest Substring with At Most Two Distinct Characters

    ID: 44171 Type: Default 1000ms 256MiB

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 contiguous substring that contains at most two distinct characters.

Example: For s = "eceba", the longest substring is "ece" which has length 3.

This problem requires an efficient solution, ideally using the sliding window technique. In mathematical terms, if we define a substring as s[i...j] then find the maximum value of \(j-i+1\) such that the substring contains at most two unique characters.

inputFormat

The input is provided via standard input (stdin) as a single line containing a string s consisting of English letters. The string may be empty.

outputFormat

Output an integer to standard output (stdout) representing the length of the longest substring of s that contains at most two distinct characters.

## sample
eceba
3