Data Structures & AlgorithmsHardGATE CS · Codeforces Div 2

Array A = [8, 27, 25, 23, 28, 20, 13] (all values below 32). What is the maximum of A[i] XOR A[j] over all index pairs with 0 ≤ i < j < 7?

  1. A. 31
  2. B. 55
  3. C. 2
  4. D. 25

Correct answer: A. 31

Inserting the values into a binary trie and choosing the opposite bit at each level finds the pair with XOR 31. Checking only neighbouring positions, or maximising the sum, gives other numbers.

More Trees, Graphs, Recursion and Dynamic Programming questions

Exams that ask this topic