Data Structures & AlgorithmsHardCodeforces Div2 D · bitwise tries

Problem: What is the maximum XOR of any two different elements of the array [3, 10, 5, 25, 2, 8]?

Problem: What is the maximum XOR of any two different elements of the array [3, 10, 5, 25, 2, 8]?
a = [3, 10, 5, 25, 2, 8]
print(max(x ^ y for i, x in enumerate(a) for y in a[i + 1:]))
What is printed?
  1. A. 27
  2. B. 28
  3. C. 25
  4. D. 31

Correct answer: B. 28

The maximum comes from 5 XOR 25 = 28. A binary trie solves the same question in O(n * 31) time, which is the intended approach for large n.

More Coding Interview Problems questions

Exams that ask this topic