#K79562. Adjacent Removal Count
Adjacent Removal Count
Adjacent Removal Count
You are given a string s
. Your task is to calculate the minimum number of removals required so that every character in the string appears at most once. In each removal operation, you may remove a single character from any position. The goal is to achieve a string where all characters are unique.
Note: The removal operation is not restricted to only adjacent characters even though the problem statement mentions 'adjacent removals'. Overall, you simply need to remove the extra occurrences of each character. For example, if a character appears k times, you must remove k−1 of its occurrences.
Examples:
s = "aabbcc"
requires 3 removals (one removal for each duplicate group: 'a', 'b', and 'c').s = "abcabc"
requires 3 removals.s = "aabb"
requires 2 removals.s = "abc"
requires 0 removals.
The input will consist of multiple test cases. For each test case, print the minimum number of removals required on a separate line.
inputFormat
The first line of the input contains an integer T
(1 ≤ T ≤ 105), the number of test cases. Each of the next T
lines contains a single string s
, which may be empty and consists of lowercase and/or uppercase English letters.
outputFormat
For each test case, output a single integer on a new line representing the minimum number of removals needed to make all characters in the string unique.
## sample5
aabbcc
abcabc
aabb
abc
a
3
3
2
0
0
</p>