Data Structures & AlgorithmsHardProduct Company SDE · ICPC regional

Problem: What is the maximum value of a XOR b over all pairs (a, b) taken from the array [3, 10, 5, 25, 2, 8] (a and b may be equal)?

  1. A. 29
  2. B. 35
  3. C. 28
  4. D. 31

Correct answer: C. 28

A bitwise trie (or checking all pairs) finds 5 XOR 25 = 00101 XOR 11001 = 11100 = 28. Using OR instead gives 25 | 5 = 29, maximising the sum gives 35, and XOR-ing the whole array gives 31.

More Coding Interview Problems questions

Exams that ask this topic