Maximizing XOR Discussions | Algorithms | HackerRank
  • + 0 comments

    Lots of naive solutions in the comments. Here is a Python solution:

    def maximizingXor(l, r):
        count = 0
        while r != l:
            r >>= 1
            l >>= 1
            count += 1
        return (1 << count) - 1