We need to find a number y in the range of L,R so that X^Y is maximum.
Here L,R are indexes of array or any two integers from which we need to need to find y.
L,R range doubt
While solving this question using trie.
- At each node of the trie, we will store the ith bit of the number for a query of type 0.
- To solve the query of type 1 we will store the indexes of the number that pass through that node.
- When we go down the tree during a query and maximizing the xor, we go in a direction that contains at least one index in range L to R, otherwise, we will go in the other direction.
- To search if at least one index is within the stored indexes we will use binary search.
(Since the indices will always be positive, you can apply count sort on them. That will do your work in linear time.)