#C10333. Minimum Unique Characters Substring

    ID: 39527 Type: Default 1000ms 256MiB

Minimum Unique Characters Substring

Minimum Unique Characters Substring

Given a string s, find the minimum length of a contiguous substring that contains all the unique characters present in s exactly once. In other words, let U be the set of all distinct characters in s. You are required to find the smallest window such that each character in U appears exactly once in that window.

The solution should utilize an efficient sliding window technique. For example, for the input string "abcabcbb", the unique characters are {a, b, c} and one possible minimum substring is "abc" (length 3), which is the expected result.

Note: The input is read from standard input (stdin) and output should be written to standard output (stdout).

inputFormat

The input begins with an integer T (1 ≤ T ≤ 100), representing the number of test cases. Each of the following T lines contains a non-empty string s consisting of printable ASCII characters.

outputFormat

For each test case, output a single line containing the minimum length of a contiguous substring that contains all the unique characters of s exactly once.

## sample
3
abcabcbb
bbcaraca
zabcz
3

4 4

</p>