Data Structures & AlgorithmsHardCodeforces Div 2 · ICPC regional

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

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

Correct answer: A. 21

Walking the trie with subtree counts, only pairs whose XOR is strictly below 25 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