r/programmingchallenges • u/mindlessCoder • Sep 15 '18
Find maximum xor
I was asked this question in an interview. Given three numbers L, R, X. We have to find a number Y such that Y⊕X is maximum and Y lies between L and R (both inclusive). One way is to use brute force and check all numbers from L to R but can we do better than this?
8
Upvotes
View all comments
Show parent comment
2
u/Introscopia Sep 15 '18
it's basically the largest number N lesser than or equal to R for which N&X equals 0.
it's really tricky. Who were you interviewing with, Satan?