Doubt regarding the editorial

After observing the technique to get first bit, we can see that if we XOR L and R, the most significant bit of this XOR will tell us the maximum value we can achieve i.e. let XOR of L and R is 1xxx where x can be 0 or 1 then maximum XOR value we can get is 1111 because from L to R we have all possible combination of xxx and it is always possible to choose these bits in such a way from two numbers such that their XOR becomes all 1.

I want to ask how do we know that after 1xxx , xxx will have all possible combination between 2 numbers?

It is based on logic that, if L xor R is 1xxx, then the number 1000 would be greater than L and less than equal to R and the number 111 would be also greater than L and less than R, their xor would be 1111, which means all x could be 1

1 Like

Oh! So you mean that for L xor R= 1xxx
There will be two numbers 1000 and 111 falling between L and R and therefore these will give us 1111.

yes, so if L xor R is 1xxx, max xor would be 1111

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.