#K68382. Maximum Distinct Characters After a Single Change
Maximum Distinct Characters After a Single Change
Maximum Distinct Characters After a Single Change
You are given a string s. You are allowed to change exactly one character of s to any other character. The task is to maximize the number of distinct characters in the resulting string.
Let \( d = |\{c : c \text{ is in } s\}| \) be the number of distinct characters in s and \( n = |s| \) be the length of s. Then the answer is given by:
[ \text{answer} = \begin{cases} d &\text{if } d = n, \ d + 1 &\text{if } d < n. \end{cases} ]
Your program should read from stdin and output the answer for each test case to stdout.
inputFormat
The input consists of multiple test cases. The first line contains an integer t representing the number of test cases. Each of the next t lines contains a non-empty string s composed of lowercase letters.
Input Format:
t s1 s2 ... st
outputFormat
For each test case, output a single line containing the maximum number of distinct characters that can be obtained by changing exactly one character in s.
## sample3
abca
abcde
zzzzz
4
5
2
</p>