#C1426. Longest Distinct Character Subsegment

    ID: 43889 Type: Default 1000ms 256MiB

Longest Distinct Character Subsegment

Longest Distinct Character Subsegment

You are given a string s. Your task is to determine the length of the longest contiguous substring that contains only distinct characters. In other words, find the maximum length of any segment of s where every character is unique.

For example, if s = "abcabcbb", the longest substring with all distinct characters is abc with a length of $3$.

Note: If the string is empty, the answer is $0$.

Input/Output Format: The input is read from standard input (stdin) and the output is written to standard output (stdout).

Mathematical Formulation: Given a string \(s = s_1s_2\ldots s_n\), find the maximum \(k\) such that there exists an index \(i\) with \(1 \leq i \leq n-k+1\) satisfying \(s_i, s_{i+1}, \ldots, s_{i+k-1}\) are all unique. That is, the answer is:

[ \max_{1 \leq i \leq n} { k \mid s_i, s_{i+1}, \ldots, s_{i+k-1} \text{ are all distinct} } ]

inputFormat

The first line contains an integer T (the number of test cases). Each of the following T lines contains a single string s.

Constraints:

  • 1 ≤ T ≤ 104
  • The length of each string does not exceed 105.
  • s consists of printable ASCII characters (without spaces).

outputFormat

For each test case, output a single integer representing the length of the longest contiguous substring of s that contains all distinct characters. Each result should be printed on its own line.

## sample
3
abcabcbb
bbbbb
pwwkew
3

1 3

</p>