#C7204. Longest Substring with At Most Two Distinct Characters

    ID: 51050 Type: Default 1000ms 256MiB

Longest Substring with At Most Two Distinct Characters

Longest Substring with At Most Two Distinct Characters

You are given a string s. Your task is to find the length of the longest substring that contains at most two distinct characters.

For example, if s = "eceba", the longest substring that contains at most two distinct characters is "ece" which has length 3.

This problem requires an efficient solution using the sliding window technique to keep track of the characters in the current substring. The use of appropriate data structures is essential to achieve optimal performance.

Note: Substrings are continuous segments of the original string.

inputFormat

The first line of input contains an integer t representing the number of test cases. Each of the following t lines contains a non-empty string s.

Input is read from stdin.

outputFormat

For each test case, output a single integer representing the length of the longest substring that contains at most two distinct characters. Each answer should be printed on a new line to stdout.

## sample
3
eceba
ccaabbb
abcabc
3

5 2

</p>