Maximizing XOR Discussions | Algorithms | HackerRank
  • + 1 comment

    Consider this: https://www.hackerrank.com/challenges/maximizing-xor/submissions/code/44305239

    1. Strip your number down to the most significant bit followed by some amount of 0s or 1s thereafter. This can be done using l^r. The first time one of the numbers has a 1 and the other doesn't, this will be your most significant bit.
    2. Set all the following 0s to 1s. If 1000 is your most significant, the maximum will be 1111.
    3. Print the decimal interpretation of the resulting binary number.