You have to find the minimum number of operations to make all the elements of the array ‘ARR’ equal. It is guaranteed that all elements of the array can be made equal using some operations.
The first line of input contains an integer ‘T’, denoting the number of test cases.
The first line of each test case contains an integer ‘N’, denoting the length of the array.
For each test case, print the minimum number of operations to make all the elements of the array equal.
Output for each test case is printed on a separate line.
Note:
You do not need to print anything. It has already been taken care of. Just implement the given function.
Constraints:
1 <= T <= 1000
1 <= N <= 10^9
Time Limit: 1 sec
Follow Up:
Can you do this in constant time and space?
Sample Input 1:
2
1
3
Sample Output 1:
0
2
Explanation For Sample Input 1:
For the first test case,
Initially, the array ‘ARR’ is [1]. Since the array has only a single element therefore it will require 0 operations to make all array elements equal. So the output is 0.
For the second test case,
Initially, the array ‘ARR’ is [1, 3, 5]. So in the first operation, we will increment element 1 by one and decrement element 5 by one and the updated array will look like [2, 3, 4].
Then we perform a second operation in which we will increment 2 by one and decrement element 4 by one and the updated array will look like [3, 3, 3]. So finally all the elements of the array become equal in 2 operations. So the output is 2.
Sample Input 2:
2
6
5
Sample Output 2:
9
6