#K66817. Minimum Operations to Equal Health Indices
Minimum Operations to Equal Health Indices
Minimum Operations to Equal Health Indices
You are given t test cases. In each test case, there are n plants with given health indices. Your task is to compute the minimum number of operations required to make all the health indices equal. In one operation, you can change the health index of a plant to any other integer.
The optimal strategy is to choose the health index that appears most frequently and then change the remaining plants' health indices. Mathematically, if the maximum frequency is \(f\) and there are \(n\) plants, the minimum number of operations is:
[ \text{minOperations} = n - f ]
Note: You need to read from standard input (stdin) and print the results to standard output (stdout) for each test case.
inputFormat
The first line contains an integer t (1 ≤ t ≤ 20,000) representing the number of test cases. The description of t test cases follows.
For each test case:
- The first line contains an integer n (1 ≤ n ≤ 200,000), the number of plants.
- The second line contains n integers, where the ith integer represents the health index of the ith plant. Each health index is in the range \(-10^9\) to \(10^9\).
outputFormat
For each test case, output a single integer, which is the minimum number of operations required to equalize all health indices. Each answer should be printed on a new line.
## sample1
3
4 4 4
0
</p>