Data Structures & AlgorithmsHardICPC regional · GATE CS top band

Array A = [1, 16, 18, 4, 25, 5, 13, 21]. How many index pairs i < j satisfy (A[i] XOR A[j]) < 23? (A trie with subtree counts answers this in O(n·bits); the answer here is a plain integer.)

  1. A. 22
  2. B. 21
  3. C. 7
  4. D. 28

Correct answer: B. 21

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