I solved it in Brute f tech Can you please tell me an efficient way to solve this problem please help
I solved it in Brute f tech Can you please tell me an efficient way
See this, you will get the intution
consider pattern of binary values from L to R. We can see that first bit from L to R either changes from 0 to 1 or it stays 1 i.e. if we take the XOR of any two numbers for maximum value their first bit will be fixed which will be same as first bit of XOR of L and R itself.
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.
Examples 1:
L = 8 R = 20
L ^ R = (01000) ^ (10100) = (11100)
Now as L ^ R is of form (1xxxx) we
can get maximum XOR as (11111) by
choosing A and B as 15 and 16 (01111
and 10000)
Examples 2:
L = 16 R = 20
L ^ R = (10000) ^ (10100) = (00100)
Now as L ^ R is of form (1xx) we can
get maximum xor as (111) by choosing
A and B as 19 and 20 (10011 and 10100)
So the solution of this problem depends on the value of (L ^ R) only. We will calculate the L^R value first and then from most significant bit of this value, we will add all 1s to get the final result.

what is right shift equal to means???
Right Shift :
Denoted as : >>
Eg: N>>i (N: first operand, i: second operand)
Takes two numbers, right shifts the bits of the first operand, the second operand decides the number of places to shift. In other words right shifting an integer “ x ” with an integer “ y ” denoted as ‘ (x>>y) ‘ is equivalent to dividing x with 2^y.
eg: lets take N=32 ; which is 100000 in Binary Form.
Now, if “ N is right-shifted by 2” i,e N=N>>2 then N will become N=N/(2^2). Thus, N=32/(2^2)=8 which can be wriiten as 1000
I know this one but in code you have written two<<=1 what does this mean<<=/>>=
this means nothing but
x <<= 1 x = x<<1
also,
y <<= 1 y = y<<1
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.