Data Structures & AlgorithmsHardICPC regional · GATE CS top band

A binary trie of 6-bit numbers stores the set S = [23, 17, 24, 54, 21, 27, 41]. For the query x = 40, what is the maximum value of x XOR s over all s in S? (Answer as a decimal integer.)

  1. A. 63
  2. B. 40
  3. C. 30
  4. D. 1

Correct answer: A. 63

A greedy walk down the trie that prefers the opposite bit at every level finds the maximum 63. Only checking the largest stored element, or picking the smallest XOR, are the usual slips.

More Trees, Graphs, Recursion and Dynamic Programming questions

Exams that ask this topic