#C3399. Minimum Operations to Equalize Elements
Minimum Operations to Equalize Elements
Minimum Operations to Equalize Elements
Given an array of integers, your task is to determine the minimum number of operations required to make all elements equal. In one operation, you can choose any two distinct indices \(i\) and \(j\) (with \(1 \leq i, j \leq N\) and \(i \neq j\)) and set \(A[i] = A[j]\). The optimal strategy is to change all elements to the most frequent element. Mathematically, if \(\text{max\_freq}\) is the frequency of the most common element, then the answer is \(N - \text{max\_freq}\).
Input and Output: The input is provided via standard input and the output must be printed to standard output.
inputFormat
The first line contains an integer \(T\) denoting the number of test cases. Each test case consists of two lines. The first line contains an integer \(N\) indicating the number of elements in the array. The second line contains \(N\) space-separated integers representing the array elements.
outputFormat
For each test case, output a single line with the minimum number of operations required to make all elements equal.
## sample2
4
1 2 3 4
5
10 10 10 10 10
3
0
</p>