Data Structures & AlgorithmsHardGATE CS · Codeforces Div 2

Array A = [17, 0, 16, 23, 30, 19, 8, 11, 10]. How many index pairs i < j satisfy (A[i] XOR A[j]) < 13? (A trie with subtree counts answers this in O(n·bits); the answer here is a plain integer.)

  1. A. 26
  2. B. 14
  3. C. 23
  4. D. 13

Correct answer: D. 13

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