#K83762. Make Array Elements Unique
Make Array Elements Unique
Make Array Elements Unique
You are given an array of integers, and your task is to perform operations so that all array elements become unique. In each operation, you can choose a duplicate element and increment it by 1 until it reaches a value that is not already present in the array. More formally, for an integer (x) that appears more than once, you can repeatedly replace a duplicate (x) by (x+1) until all occurrences are unique.
You will be given (T) test cases. Each test case begins with an integer (N), the number of elements, followed by a line with (N) space-separated integers. Your goal is to compute the minimum number of such operations required for each test case.
inputFormat
The first line of the input contains an integer (T) denoting the number of test cases. Each test case consists of two lines: the first line contains an integer (N) (the size of the array), and the second line contains (N) space-separated integers representing the array elements.
outputFormat
For each test case, output a single integer on a new line representing the minimum number of operations required to make all the array elements distinct.## sample
4
3
4 5 5
4
6 6 6 6
5
1 2 3 2 1
4
1 2 3 4
1
3
2
0
</p>