Trie interview question


giving run time error,what should i do?

Hello @Vibhuti0206

I think your approach to solve this problem is wrong.

We need to find two Non overlapping ranges with maximum XOR sum of the two ranges.
HINT to solve the problem

  1. int result = 0;
  2. Traverse the array, let say we are at index “i”, we consider index “i” to be the end of the first range
  3. Get the maximum sub array xor for elements upto index “i”, sub array ending at index “i” (Let it be x1)
    // This part is simply the maximum XOR subarray question
  4. Implement some function say “GetRightXORMax” which return the maximum sub array xor from index “i + 1” to end of the array (Let it be x2) // This function should be implemented in O(1) time complexity.
  5. if(x1 + x2 > result) {
  6. result = x1 + x2
  7. }
  8. print result;

Here is the code

I hope I’ve cleared your doubt. I ask you to please rate your experience here
Your feedback is very important. It helps us improve our platform and hence provide you
the learning experience you deserve.

On the off chance, you still have some questions or not find the answers satisfactory, you may reopen
the doubt.