My code is working fine but it is not passing any of the test cases
Try this:
Will you please elaborate how program is working?
Calculate the most significant bit having different set bits in l and r. after this all bits of max xor having less significant than this bit is 1.