#C4398. Largest Non-Adjacent Character Subset

    ID: 47931 Type: Default 1000ms 256MiB

Largest Non-Adjacent Character Subset

Largest Non-Adjacent Character Subset

You are given a string s. The task is to determine the size of the largest subset of characters from s such that no two characters in the subset are adjacent in the original string. In other words, you are allowed to select characters from s as long as no two selected characters were consecutive in the input.

Upon closer inspection of the provided examples, it turns out that the answer is simply the number of distinct characters in the string. For instance, in the string "aabbccd", the distinct characters are 'a', 'b', 'c', and 'd', thus the answer is 4.

Note: Although the problem statement mentions non-adjacency, the examples imply that you only need to count the unique characters.

inputFormat

The input begins with a single integer t on the first line, indicating the number of test cases. Each of the following t lines contains a single string s.

Input Format:

t
s1
s2
...
s_t

outputFormat

For each test case, output a single integer on a new line representing the size of the largest subset of characters (i.e. the number of distinct characters) chosen from the string such that no two characters are adjacent in the original string.

Output Format:

result_1
result_2
...
result_t
## sample
3
aabbccd
abc
aabbccddeeffgg
4

3 7

</p>