I tried with this aprroach


since time complexity is O(n)
but passing only 1 testcase please review

your Brute Force will work correctly but not for input as large as 10^9 .So it is beneficial to use Tries as its use along with binary search reduces the time complexity of program for an input as large as 10^9. While solving this question using trie.

  1. At each node of the trie, we will store the ith bit of the number for a query of type 0.
  2. To solve the query of type 1 we will store the indexes of the number that pass through that node.
  3. 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.
  4. 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.)

Now, keeping above in mind, try to correct your code.

Hope, this would help.