#K66137. Equalize Array Elements
Equalize Array Elements
Equalize Array Elements
You are given an array of integers. In one operation, you can change any element to any other integer that already exists in the array. The task is to determine the minimum number of operations needed to make all the elements of the array equal.
It can be proven that the answer is exactly the number of distinct elements minus one. In mathematical terms, if (U) is the set of unique elements in the array, the minimum number of operations is: $$|U| - 1.$$
inputFormat
The input is read from standard input (stdin).
The first line contains an integer (T), the number of test cases. Each test case consists of two lines. The first line contains an integer (n) specifying the length of the array. The second line contains (n) space-separated integers representing the array elements.
outputFormat
For each test case, output a single integer on a new line which is the minimum number of operations required to make all elements equal. The output is written to standard output (stdout).## sample
4
3
1 2 3
4
10 10 10 10
5
1 2 2 1 1
5
1000000000 -1000000000 0 999999999 -999999999
2
0
1
4
</p>