Data Structures & AlgorithmsVery hardProduct company OA

A binary trie over 4-bit numbers finds the maximum XOR of any pair from [3, 10, 5, 9, 2, 8]. What is the maximum XOR?

  1. A. 13
  2. B. 15
  3. C. 11
  4. D. 14

Correct answer: B. 15

For each number, walk the trie from the top bit choosing the opposite bit when possible. 5 = 0101 and 10 = 1010 differ in every bit: 5 XOR 10 = 1111 = 15, the maximum possible for 4 bits. 3 XOR 10 = 9 and 5 XOR 8 = 13 are smaller.

More Trees, Graphs, Recursion and Dynamic Programming questions

Exams that ask this topic