#C5292. Minimum Transformations
Minimum Transformations
Minimum Transformations
You are given T test cases. For each test case, you are given an integer n followed by an array of n integers.
Your task is to determine the minimum number of transformations required to make all elements of the array equal. A transformation is defined as an operation that can modify the array toward uniformity. If the array is initially uniform (i.e. \(a_1 = a_2 = \cdots = a_n\)), then no transformation is needed so the answer is 0.
If it is impossible to transform the array into one where all the elements are equal, output -1
.
Note: The transformation process is abstract. Based on the problem logic, if the array is not uniform then it is considered impossible to perform the required transformations, so the expected output in that case is always -1
.
inputFormat
The first line contains an integer T — the number of test cases.
For each test case:
- The first line contains an integer n — the number of elements in the array.
- The second line contains n space-separated integers representing the array.
Input is given via standard input (stdin).
outputFormat
For each test case, output a single line containing the minimum number of transformations required to make all elements equal, or -1
if it is impossible.
Output the result to standard output (stdout).
## sample1
3
2 2 2
0
</p>