


Let’s say you have an array/list [1,4,4,5]. We can increase the third element by 1 and the fourth element by 1. Finally, our array will look like [1,4,5,6] where all elements are distinct. Therefore the minimum number of operations is 2.
The first line contains a single integer ‘T’ representing the number of test cases.
The first line of each test case contains a single integer ‘N’ representing the size of the array/list ‘ARR’.
The second line and the last line of input contain ‘N’ single space-separated integers representing the array/list elements.
For each test case, return the minimum number of operations to make the array distinct.
You do not need to print anything; it has already been taken care of. Just implement the function.
1 <= T <= 10
1 <= N <= 10^3
1 <= ‘ARR[i]’ <= 10^4
Time Limit: 1 sec
We will maintain the count of each element present in an auxiliary array. Finally, each element must have at most one occurrence.
We will apply the algorithm as follows:-
We will sort the array/list ‘ARR’. As we can only apply the increment operation we just need to make the array/list increasing.
Following is the algorithm for this approach: