Sunday, August 28, 2011

find 2 numbers in array with max XOR

yes u heard it right, Max XOR

sol:
create a bin tree with bits
1. if msb is 0, move left
2. if msb is 1, move right
3. till all the numbers are added

now process the array
take ith number
invert it
find the max distance in the tree
return the maximum of distance

No comments:

Post a Comment