Maximum xor profit

is there any efficient way to do this other then O(n^2)

An efficient solution is to 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.

can you explain it by taking some example
let say 11 to 15??

yeah sure lets find out value of 11 ^ 15, it is 4 binary representation of 4 is 100 So, according to the above approach the solution would be 111 i.e 7. Which is correct answer you can check that with the help of your n^2 approach.

how to say by confirm that after that set bit all combination of 1 possible is there any logic or just observation??

it is based on logic that if XOR of L and R is 1xxx then we have all possible combination of xxx between L and R so it is possible to choose two numbers that xxx becomes 111.