Hedy is securing a communication channel for a network of N torpedoes.
Each torpedo operates on a frequency represented by an integer. The frequencies are given as an array A of N integers.
To ensure secure transmission without interference, every torpedo must have a strictly unique frequency.
Hedy can increase the frequency of any torpedo by 1 any number of times.
Determine the minimum total number of increments required so that all frequencies become unique.
Input Format The first line contains an integer T, the number of test cases. For each test case: The first line contains an integer N. The second line contains N space-separated integers: A1, A2, ..., AN. Output Format
For each test case, output a single integer — the minimum total number of frequency increases required.
Input
1 4 1 2 2 3
Output
2 Explanation
Increase the second 2 to 4:
1 2 3 4
Total increments:
(3-2) + (4-3) = 2
1 ≤ T ≤ 10 1 ≤ N ≤ 2×10^5 1 ≤ Ai ≤ 10^9
Expert in Data Structures & Algorithms. Building tools to help developers crack FAANG interviews.
ICPC Algoqueen • Pending
ICPC Algoqueen • Pending
ICPC Algoqueen • Pending
Flipkart Grid 8.0 • Pending
Flipkart Grid 8.0 • Pending