Data Structures & AlgorithmsModerateCodeforces Div 2 C · ICPC regional

Among the values [3, 10, 5, 25, 2, 8], what is the maximum value of x XOR y over two different elements x and y?

  1. A. 8
  2. B. 28
  3. C. 24
  4. D. 3

Correct answer: B. 28

A bitwise trie greedily prefers the opposite bit at each level from the top, which finds the maximum XOR pair in O(n * bits). Pairs with the largest sum or AND are different quantities, which is the trap.

More Coding Interview Problems questions

Exams that ask this topic