#C8185. Minimum Operations to Unify String
Minimum Operations to Unify String
Minimum Operations to Unify String
You are given a string \(S\). In one operation, you can choose any character of \(S\) and change it to any other character. The goal is to make all characters in the string identical.
The problem is to determine the minimum number of operations required so that all characters of \(S\) become the same. Formally, if you transform the string into a string \(T\) where every character is equal, the number of operations is:
[
\text{operations} = |S| - \max_{c}{ \text{frequency of } c \text{ in } S }
]
For example:
- For \(S = \texttt{aabc}\), the most frequent character \(a\) appears twice. So, the answer is \(4 - 2 = 2\).
- For \(S = \texttt{xyz}\), each character appears once, so the answer is \(3 - 1 = 2\).
- For \(S = \texttt{zzzz}\), all characters are already the same. So, the answer is \(4 - 4 = 0\).
This function will be called once for each test case.
inputFormat
The first line of input contains an integer \(T\) representing the number of test cases. Each of the following \(T\) lines contains a non-empty string \(S\) consisting of English letters.
outputFormat
For each test case, output a single line containing the minimum number of operations required to transform the string into one where all characters are identical.
## sample3
aabc
xyz
zzzz
2
2
0
</p>