Data Structures & AlgorithmsHardICPC regional · GATE CS top band

Array A = [20, 5, 12, 11, 18, 29, 30, 31, 17]. How many index pairs i < j satisfy (A[i] XOR A[j]) < 9? (A trie with subtree counts answers this in O(n·bits); the answer here is a plain integer.)

  1. A. 15
  2. B. 9
  3. C. 7
  4. D. 29

Correct answer: C. 7

Walking the trie with subtree counts, only pairs whose XOR is strictly below 9 are added, giving 7. Including equality or swapping to '>' are the mistakes that produce the other options.

More Trees, Graphs, Recursion and Dynamic Programming questions

Exams that ask this topic