#K32912. Longest Distinct Substring

    ID: 24971 Type: Default 1000ms 256MiB

Longest Distinct Substring

Longest Distinct Substring

Given a string s, find the length of the longest substring that contains all distinct characters. In other words, determine the maximum length L such that a contiguous segment (substring) of s has no duplicate characters.

This problem can be solved efficiently using the sliding window technique. The idea is to expand the window until a duplicate is found and then shift the start of the window past the duplicate. Mathematically, you are to compute

\( L = \max_{0 \leq i \leq j < n} \{ j - i + 1 \ \vert \ s[i \ldots j] \text{ contains all distinct characters} \} \)

where n is the length of the string s.

inputFormat

The first line of input contains a single integer T, denoting the number of test cases. Each of the following T lines contains a string s for which you need to determine the length of the longest substring with unique characters.

outputFormat

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

## sample
2
abcabcbb
bbbbb
3

1

</p>