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?
- A. Sorting plus merge sort
- B. Binary trie with subtree counts
- C. Kadane's algorithm
- 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
- Problem: What is the time complexity of the Wagner-Fischer dynamic programme for edit distance on strings of length n and m?
- Problem: Which two properties define a matroid, which is what makes the greedy algorithm optimal?
- Problem: Which algorithm finds shortest paths in a grid where each cell weight is 0 or 1?
- Problem: Which technique counts subarrays with sum at most K in a non-negative array in O(n)?
- Problem: What is the time complexity of subset-sum over n items with a bitset of width W (up to 10^5)?
- Problem: What is the purpose of the low-link value in Tarjan's strongly connected components algorithm?