#C11843. Minimum Operations to Equalize Array
Minimum Operations to Equalize Array
Minimum Operations to Equalize Array
You are given multiple test cases. In each test case, you are provided with an array of n integers. In one operation, you can change the value of an element to any other integer value in order to eventually make all the elements in the array equal. The task is to compute the minimum number of operations needed so that all array elements become equal.
It can be observed that if there are k distinct elements in the array, the answer is given by \(k-1\) (when \(k>1\)) because you can change each group of elements having a unique value to a common value one by one. If the array already contains all equal elements, 0 operations are needed.
inputFormat
The first line contains an integer T representing the number of test cases. For each test case:
- The first line contains an integer n representing the number of elements in the array.
- The second line contains n space-separated integers representing the elements of the array.
outputFormat
For each test case, output a single integer on a new line - the minimum number of operations required to make all elements equal.
## sample3
3
4 4 4
4
3 1 2 1
5
1 1 1 1 1
0
2
0
</p>