#K86537. Longest Substring Without Repeating Characters

    ID: 36886 Type: Default 1000ms 256MiB

Longest Substring Without Repeating Characters

Longest Substring Without Repeating Characters

You are given a string s. Your task is to determine the length of the longest substring of s that contains only distinct characters.

For example, if s = "abcabcbb", then the longest substring with all unique characters is "abc", which has a length of 3. Solve this problem using an efficient approach, such as the sliding window technique.

The solution should involve processing multiple test cases. For each test case, first, a line containing an integer T is provided, followed by T lines, each containing a string.

Mathematically, if we define a substring s[i...j] such that all characters are distinct, you need to maximize its length, i.e., find:

\( \max_{i,j: s[i...j] \text{ has all unique characters}} (j-i+1) \)

inputFormat

The first line of input contains an integer T, the number of test cases. The following T lines each contain one string for which you need to compute the answer.

The input should be read from standard input.

outputFormat

For each test case, output a single integer representing the length of the longest substring with all distinct characters, each on a new line.

The output should be printed to standard output.

## sample
3
abcabcbb
bbbbb
pwwkew
3

1 3

</p>