#K52517. Minimum Operations to Equalize Array Elements

    ID: 29327 Type: Default 1000ms 256MiB

Minimum Operations to Equalize Array Elements

Minimum Operations to Equalize Array Elements

You are given an array of integers. In one operation, you can change any element to any value. Your task is to determine the minimum number of operations required to make all the elements of the array equal.

Observation: The optimal strategy is to convert all elements to the value that appears most frequently in the array. Thus, the answer is \(N - f_{max}\), where \(N\) is the number of elements and \(f_{max}\) is the frequency of the most common element.

This problem requires you to handle multiple test cases. For each test case, the first input line is an integer \(N\) (the number of elements) followed by a line with \(N\) space separated integers. Output the minimum operations required on a new line for each test case.

inputFormat

The first line of input contains an integer \(T\), denoting the number of test cases. Each test case consists of two lines. The first line contains an integer \(N\) representing the number of elements in the array. The second line contains \(N\) space-separated integers.

Example:

2
3
2 3 5
4
1 1 1 1

outputFormat

For each test case, output a single integer on a new line, which is the minimum number of operations required to make all the array elements equal.

Example:

2
0
## sample
2
3
2 3 5
4
1 1 1 1
2

0

</p>