#C7536. Minimum Operations to Equalize Array

    ID: 51418 Type: Default 1000ms 256MiB

Minimum Operations to Equalize Array

Minimum Operations to Equalize Array

You are given an array of integers. In one operation, you can choose one distinct element from the array and change all of its occurrences to any other value that is already present in the array. The goal is to make all elements in the array equal with the minimum number of operations. It can be shown that the minimum number of operations required is (k-1), where (k) is the number of distinct elements in the array.

inputFormat

The input is read from standard input (stdin) and has the following format:\n\n1. The first line contains a single integer (t) (the number of test cases).\n2. For each test case, the first line contains a single integer (n) (the number of elements in the array).\n3. The second line of each test case contains (n) integers separated by spaces, representing the elements of the array.

outputFormat

For each test case, output a single line containing one integer -- the minimum number of operations required to make all elements of the array equal.## sample

3
3
1 1 1
4
2 4 8 16
5
6 6 6 6 12
0

3 1

</p>