
1. Consider 0 based indexing in ‘ARR’.
The first line contains a single integer ‘T’ representing the number of test cases.
The first line of each test case will contain three space-separated integers ‘N’, ‘LOW’, and ‘HIGH’ respectively representing the size of ‘ARR’ and the two integers that Ninja have between which the xor of every beautiful pair must lie.
The second line of each test case will contain ‘N’ space-separated integers representing array/list ‘ARR’.
For each test case, print a single integer representing the number of beautiful pairs in ‘ARR’.
Output for every test case will be printed in a separate line.
You don’t need to print anything; It has already been taken care of.
1 <= T <= 50
1 <= N <= 10000
1 <= ARR[i] <= 20000
1 <= LOW <= HIGH <= 20000
Where ‘T’ is the number of test cases, 'N' is the size of ‘ARR’, and ‘LOW’, ‘HIGH’ are the integers that Ninja have, ‘ARR[i]’ is the ‘i-th’ element of arraylist ‘ARR’
Time limit: 1 sec
The basic idea is to initialize an integer variable ‘COUNTER’: = 0 and one by one find the XOR of each valid pair of integers in ‘ARR’. If for a pair xor is in the range [‘LOW’, ‘HIGH’] then increment ‘COUNTER’ by 1.
The steps are as follows:
The basic idea is to use trie to solve this problem. Trie here is basically a rooted binary tree where each edge is either labelled by 0 or 1 and the node will have a value equal to the number of elements in the trie having a prefix given by path from the root to that node.
We iterate over the given array ‘ARR’ and for each integer in ‘ARR’ count the number of elements present in the Trie whose bitwise XOR with the current integer is in the range [LOW, HIGH], and then insert this integer in the trie by converting it in 16-bit binary format.
Let F(X) be the number of elements in the trie whose bitwise XOR with a current integer is less than ‘X’, then we need to find F(HIGH+1) - F(LOW).
We can find F(X) as follow -:
Now the complete problem can be solved by using this algorithm of finding F(X) as follows -:
Complete String
Complete String
Complete String
Complete String
Complete String
Complete String
Similar Name
Similar Name
Similar Name
Similar Name
Auto Suggestion
Auto Suggestion
Auto Suggestion
Auto Suggestion
Auto Suggestion
Auto Suggestion
Palindrome Pairs
Design Search Autocomplete System
Design Search Autocomplete System
Design Search Autocomplete System
Design Search Autocomplete System
Design Search Autocomplete System
Design Search Autocomplete System