Maximizing XOR Discussions | Algorithms | HackerRank
  • + 11 comments

    Is there any other solution with less time complexity.

    static int maxXor(int l, int r) {
        int xor = l ^ r;
        int a = 0;
        while(Math.pow(2,a)< xor)a++;
        return (int)Math.pow(2,a) - 1 ;
    }