#K82072. Maximum Suffix Beauty
Maximum Suffix Beauty
Maximum Suffix Beauty
Given a string S, define the beauty of any suffix as the number of distinct characters it contains. In other words, for any suffix S[i..n-1] of S (where 0 ≤ i < n and n is the length of S), its beauty is defined as ( \text{beauty}(S[i..n-1]) = |{\text{characters in } S[i..n-1]}| ).
Your task is to compute, for each test case, the maximum beauty among all possible suffixes of the given string.
For example, consider S = "abac":
- Suffix "c" has beauty 1 (only 'c').
- Suffix "ac" has beauty 2 (distinct characters 'a' and 'c').
- Suffix "bac" has beauty 3 (distinct characters 'b', 'a', 'c').
- Suffix "abac" has beauty 3 (distinct characters 'a', 'b', 'c').
The maximum beauty is 3.
Input: The first line contains an integer T, the number of test cases. Each of the next T lines contains a string for which the maximum suffix beauty must be computed.
Output: For each test case, output an integer representing the maximum beauty of any suffix in the corresponding string. Each answer should be printed on a new line.
inputFormat
The input is read from standard input (stdin). The first line contains an integer T (1 ≤ T ≤ 10^5), denoting the number of test cases. Following this, there are T lines, each containing a non-empty string S consisting of lowercase English letters.
outputFormat
For each test case, output a single integer on a new line—the maximum beauty (number of distinct characters) among all suffixes of the given string S.## sample
3
abac
zzz
abcde
3
1
5
</p>