


The first line of input contains an integer 'T' representing the number of test cases or queries to be processed.
Then the test case follows.
The first line of each test case contains integer N, denoting the size of the array.
The second line of each test case contains 'N' single space-separated integers representing the array elements.
For each test case, print a single integer denoting the maximum sum, in a single line.
You do not need to print anything; it has already been taken care of. Just implement the given function.
1 <= T <= 10
1 <= N <= 10^5
1 <= ARR[i] <= 10^5
Where 'ARR[i]' denotes the 'ith' element of the array.
Time Limit: 1 sec
The key point to notice here is that in the given problem that we don’t need to delete anything from the array while selecting arr[i] from the array. We just only care about whether we select any number arr[i] from the array then we cant select the arr[i]+1 and arr[i]-1 from the array to maximize the sum in the next steps. So we will find the maximum number max in the array and create a new auxiliary array of the size max+1 that stores the number of occurrences of each unique element in the array. The count is stored in an auxiliary array at their respective index.
Now the problem is to find the maximum sum of a subsequence of the array where the subsequence does not contain adjacent elements of the array. This problem is similar to the 0/1 Knapsack Problem in which in the recursion call at any index, we have two choices whether to include that element in sum or exclude that element. Now if we choose the current number to add to the sum then recur for index i+2 or If we don’t choose the current index then recur for index i+1 and this way we find the maximum sum.
long maximumSumHelper(freq[], id):
long maximumSumHelper(freq[], id, dp[]):
The idea is to use a bottom-up dynamic programming approach instead of a memoization approach. In this, we also have two choices whether to select or not. If we select then we take the occurrences of that number and the value stored at dp[i-2] as dp[i-1] will be deleted and not be taken to count. If we do not select the number then we take dp[i-1] which have been already calculated.