#C14581. Longest Distinct Substring Lengths

    ID: 44246 Type: Default 1000ms 256MiB

Longest Distinct Substring Lengths

Longest Distinct Substring Lengths

You are given ( T ) strings. For each string, determine the length of the longest substring in which all characters are distinct. In other words, given a string ( s ) of length ( n ), find the maximum value of ( j - i + 1 ) such that all characters in the substring ( s[i \ldots j] ) are unique. This can be efficiently achieved using a sliding window technique.

For example:

  • For the string "abcabcbb", the longest substring with distinct characters is "abc" (length 3).
  • For the string "bbbbb", the longest substring is "b" (length 1).
  • For an empty string, the result is 0.

Your task is to implement a program that reads multiple strings from standard input and outputs the corresponding longest distinct substring lengths for each string.

inputFormat

The input is read from standard input (stdin). The first line contains a single integer ( T ), representing the number of test strings. This is followed by ( T ) lines, each containing a non-empty string (or possibly an empty line) for which you need to compute the length of the longest substring with all distinct characters.

outputFormat

For each input string, output a single integer on a new line representing the length of the longest substring with all distinct characters.## sample

4
abcabcbb
bbbbb
pwwkew

3

1 3 0

</p>