#K41787. Equalizing Array Elements
Equalizing Array Elements
Equalizing Array Elements
You are given T test cases. Each test case consists of an integer n followed by n space-separated integers forming an array. Your task is to compute the minimum number of moves required to make all elements of the array equal. In a single move, the optimal strategy is to make all elements equal by reducing the difference between the maximum and minimum elements of the array, which is calculated as \(\text{moves} = \max(\text{nums}) - \min(\text{nums})\). If all elements are already equal, no moves are needed (i.e. the answer is 0).
inputFormat
The first line of input contains an integer T, denoting the number of test cases. For each test case, the first line contains an integer n, the number of elements in the array. The next line contains n space-separated integers representing the array.
outputFormat
For each test case, output a single line containing the difference between the maximum and minimum element of the array, which represents the minimum number of moves required to make all the array elements equal.
## sample3
4
1 2 3 4
2
7 7
6
3 3 3 3 5 5
3
0
2
</p>