

Let,
N = 4
ARR = [2, 1, 0, 3]
Answer:- 10 (1 + 2 + 3 + 4) (The re-ordered array is [0, 1, 2, 3], so the MEXs will be 1, 2, 3, and 4).
The first line contains a single integer ‘T’ representing the number of test cases. Then each test case follows.
The first line of each test case contains an integer ‘N’ denoting the length of the array given.
The next line of every test case contains ‘N’ integers containing the elements of the array arr.
For each test case, print an integer denoting the maximum sum possible.
The output of each test case should be printed in a separate line.
You are not required to print anything, it has already been taken care of. Just implement the function.
1 <= T <= 5
1 <= N <= 10^5
1 <= ARR[i] <= 10^9
Time Limit: 1 sec
We can observe that it is always optimal to put a unique element rather than a repeated element because a repeated element does not increase the MEX of an array. So we will first put the unique elements of the array in ascending order first, then we will put the rest of the elements.