#C8772. Smallest Special Substring
Smallest Special Substring
Smallest Special Substring
You are given a string s
consisting only of the characters x
, y
, and z
. Your task is to find the length of the smallest contiguous substring that contains at least one occurrence of each of these three characters. If no such substring exists, output -1
.
Input Example:
3 xyzzxy xyz xxxxx
Output Example:
3 3 -1
Explanation: In the first test case, the substring "zxy" (or any other valid substring) has length 3 and contains all three characters 'x', 'y', and 'z'.
inputFormat
The input is read from stdin and has the following format:
- The first line contains an integer
T
representing the number of test cases. - Each of the next
T
lines contains a non-empty strings
made up solely of the characters 'x', 'y', and 'z'.
outputFormat
For each test case, output a single line containing the length of the smallest substring of s
that contains at least one occurrence of 'x', 'y', and 'z'. If such a substring does not exist, output -1
.
3
xyzzxy
xyz
xxxxx
3
3
-1
</p>