Data Structures & AlgorithmsHardICPC regional · GATE CS top band

Array A = [5, 20, 23, 4, 3, 30, 2, 24]. How many index pairs i < j satisfy (A[i] XOR A[j]) < 19? (A trie with subtree counts answers this in O(n·bits); the answer here is a plain integer.)

  1. A. 16
  2. B. 15
  3. C. 13
  4. D. 24

Correct answer: B. 15

Walking the trie with subtree counts, only pairs whose XOR is strictly below 19 are added, giving 15. 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