I kind of understood the approach, but I am not very sure about the implementation. Can you please explain me the approach again? So that I can put it into a code?
Subarray with Maximum XOR
Hey @gptradhika1208 ,
This is the algorithm, Make sure you understand the algorithm properly and then only you code it and make sure you understand the different implementation of trie data structure
- Create an empty Trie. Every node of Trie is going to
contain two children, for 0 and 1 value of bit.- Initialize pre_xor = 0 and insert into the Trie.
- Initialize result = minus infinite
- Traverse the given array and do following for every
array element arr[i].
a) pre_xor = pre_xor ^ arr[i]
pre_xor now contains xor of elements from
arr[0] to arr[i].
b) Query the maximum xor value ending with arr[i]
from Trie.
c) Update result if the value obtained in step
4.b is more than current value of result.
Hope it helps
.
If your doubt is now resolved please mark it as resolved and rate me accordingly .
Else you can further questions here .
Thankyou
Thankyou , it really helped!