#K39172. Longest Substring with At Most Two Distinct Characters

    ID: 26362 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. For example, if s = "eceba", the longest substring meeting the criteria is "ece" with length 3.

You can formalize the problem using the sliding window technique. More specifically, let \( s \) be a string, and let \( f(s) \) be the length of the longest substring that contains at most two unique characters. Your goal is to compute \( f(s) \).

Note: The input string can be empty, in which case the answer is 0.

inputFormat

The input consists of a single line containing the string s. The string may be empty and will only contain ASCII characters.

outputFormat

Output a single integer representing the length of the longest contiguous substring of s that contains at most two distinct characters.

## sample
eceba
3