Data Structures & AlgorithmsVery hardICPC regional · bitwise tries

Problem: Which technique counts pairs in an array whose XOR is less than K in O(n * bits) time?

  1. A. Sorting plus merge sort
  2. B. Binary trie with subtree counts
  3. C. Kadane's algorithm
  4. D. Dijkstra's algorithm

Correct answer: B. Binary trie with subtree counts

Walking the trie for each value counts the partners whose XOR is smaller at each bit where K has a 1.

More Coding Interview Problems questions

Exams that ask this topic