#K75157. Equalizing Array Elements
Equalizing Array Elements
Equalizing Array Elements
You are given an integer \( T \) and then \( T \) test cases. For each test case, an integer \( n \) is provided followed by \( n \) space-separated integers representing an array. Your task is to determine the minimum number of modifications required so that all elements in the array become equal, and also report the target value that all elements will have.
For each test case, if the array already has all elements equal, output 0 v
where \( v \) is the value of the elements. If there exists a value that appears more than once (i.e. the most frequent element appears at least twice), you can transform the other elements to this value. The number of modifications required is \( n - f \), where \( f \) is the frequency of the most frequent element. However, if every element in the array is unique (i.e. \( f = 1 \) and \( n > 1 \)), then it is impossible to equalize the array and you should output -1
.
Note: For a single element array (\( n = 1 \)), simply output 0 v
where \( v \) is the element itself.
inputFormat
The first line of the input contains an integer \( T \) indicating the number of test cases. Each test case is given in one line: the first number is an integer \( n \) denoting the size of the array, followed by \( n \) space-separated integers representing the array elements.
outputFormat
For each test case, output the result on a separate line. If it is possible to equalize the array, output two space-separated integers: the minimum number of modifications required and the target value. Otherwise, output -1
.
2
4 7 7 7 2
5 1 2 3 4 5
1 7
-1
</p>