#K38422. Minimum Operations to Equalize Array
Minimum Operations to Equalize Array
Minimum Operations to Equalize Array
Given an array of integers, you are allowed to perform operations that increase or decrease an element by 1. The task is to determine the minimum number of operations required to make all the elements equal. It can be proven mathematically that converting every element to the median of the array minimizes the total number of operations.
The input may include multiple test cases. For each test case, you will be given the size of the array and the array elements themselves. Your program should output the minimum number of operations for each test case on a separate line.
inputFormat
The first line of input contains an integer T, representing the number of test cases. Each test case consists of two lines:
- The first line contains an integer N, the number of elements in the array.
- The second line contains N space-separated integers 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.
## sample1
3
1 2 3
2
</p>