


Given an array arr of N integers that may contain duplicate integers. The task is to return the count of subsets of the given array such that each subset contains only distinct elements.
Note:As the answer can be large, return your answer modulo 10^9 + 7.
The first line contains an integer 'T' which denotes the number of test cases or queries to be run. Then, the T test cases follow.
The first line of each test case or query contains an integer 'N' representing the size of the array (arr).
The second line contains 'N' single space-separated integers, representing the elements in the array.
Output format:
For each test case, print the count of subsets modulo 10^9+7 in a separate line.
Note:
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
Time limit: 1 second
1
4
1 2 2 5
11
Subsets with distinct elements are: {1}, {2}, {2}, {5}, {1, 2}, {1, 2}, {2, 5}, {1,5}, {2,5}, {1, 2, 5}, {1, 2, 5}
For better understanding, let us take an array as {1, 2A, 2B, 5}
Now, subsets can be {1}, {2A}, {2B}, {5}, {1, 2A}, {1,2B}, {2A, 5}, {1, 5}, {2B,5}, {1, 2A, 5}, {1, 2B, 5}
2
5
2 3 3 6 2
3
1 1 1
17
3
First off, observe that the question focuses on subsets of the array. A very simple technique to get this done is by creating all the possible subsets. Along with keeping all the subsets, we can maintain the count of all the subsets with no duplicates.
O(2^N) per test case, where N is the number of elements.
In the worst case, we are generating all the subsets of an array. The possible number of subsets can be 2^N
O(N), where N is the number of elements.
In the worst case, we are using extra map space and a recursive stack for every subset created.