Data Structures & AlgorithmsHardGATE CS · ICPC regional

Array A = [22, 11, 12, 9, 20, 23, 25, 15, 2]. How many index pairs i < j satisfy (A[i] XOR A[j]) < 21? (A trie with subtree counts answers this in O(n·bits); the answer here is a plain integer.)

  1. A. 17
  2. B. 35
  3. C. 21
  4. D. 19

Correct answer: D. 19

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