Let Arr[] = {2, 4, 10} , A = 1 and B = 1
In this example, the binary representation of the array {2, 4, 10} is {10, 100, 1010} and according to the problem statement, only 2 fulfills the given condition, i.e., have one 0-bit count and one 1-bit count. Hence, the sum of all the numbers is 2.
Do not count zeros to the left of the most significant set bit.
The first line contains a single integer ‘T’ denoting the number of test cases to be run. Then the test cases follow.
The first line of each test case contains an integer ‘N’ denoting the array’s length.
The second line of the test case contains two integers, ‘A’ and ‘B’, denoting the number of ‘0’ bits and ‘1’ bits, respectively.
The third line of the test case contains an array ‘Arr’ of ‘N’ integers.
For each test case, print an integer denoting the sum of all numbers matching the given pattern.
Output for each test case will be printed in a separate line.
You are not required to print anything; it has already been taken care of. Just implement the function and return the answer.
1 <= T <= 10
1 <= N <= 10^5
0 <= Arr[i] <= 10^9
0 <= A <= 31
0 <= B <= 31
0 <= A + B <= 31
Time Limit: 1sec
The approach is simple; we have to calculate the total number of zeros and ones in the bitwise representation of all the given elements in our array.
The steps are as follows: