You are viewing a single comment's thread. Return to all comments →
Solution in O(g) time, where g is the MSF of (l xor r). For a 32 bit unsigned integer, worst-case g would be 32 operations.
int maxXor(int l, int r) { int a = l ^ r; int max = 0; while (a != 0) { max |= a; a = a >> 1; } return max; }
Seems like cookies are disabled on this browser, please enable them to open this website
Maximizing XOR
You are viewing a single comment's thread. Return to all comments →
Solution in O(g) time, where g is the MSF of (l xor r). For a 32 bit unsigned integer, worst-case g would be 32 operations.