Equalization of an array
Basic Accuracy: 41.05% Submissions: 795 Points: 1

Given an array of integers, the task is to count minimum number of operations to equalize the array i.e., to make all array elements same. To equalize an array, we need to move values from higher numbers to smaller numbers. Number of operations is equal to number of movements.

Input:
The first line of input contains an integer T denoting the number of test cases. Then T test cases follow. Each test case consists of two lines. First line of each test case contains an Integer N denoting size of array and the second line contains N space separated elements.

Output:
For each test case, print the minimum number of operations. And print "-1", if it is not possible to equalize the array.

Constraints:
1<=T<=100
1<=N<=105

0<=A[i]<=105

Example:
Input:

2
5
1 3 2 0 4
3
1 7 1
Output:
3
4

to report an issue on this page.

Editorial

We strongly recommend solving this problem on your own before viewing its editorial. Do you still want to view the editorial?

Yes

All Submissions

My Submissions:

Login to access your submissions.