Data Structures & AlgorithmsVery hardProduct company OA
A binary trie over 4-bit numbers finds the maximum XOR of any pair from [3, 10, 5, 9, 2, 8]. What is the maximum XOR?
- A. 13
- B. 15
- C. 11
- D. 14
Correct answer: B. 15
For each number, walk the trie from the top bit choosing the opposite bit when possible. 5 = 0101 and 10 = 1010 differ in every bit: 5 XOR 10 = 1111 = 15, the maximum possible for 4 bits. 3 XOR 10 = 9 and 5 XOR 8 = 13 are smaller.
Practise more Trees, Graphs, Recursion and Dynamic Programming questionsTrees, Graphs, Recursion and Dynamic Programming: notes and key points
More Trees, Graphs, Recursion and Dynamic Programming questions
- In a binary tree whose root is at level 0, what is the maximum number of nodes at level 5?
- A simple directed graph (no self-loops, at most one edge from u to v) has 6 vertices. What is the maximum number of edges?
- Which algorithm finds shortest paths (by number of edges) from one source in an UNWEIGHTED graph in O(V + E) time?
- A binary tree is stored in level order in a 0-indexed array (children of i at 2i + 1 and 2i + 2; None = no node): [1, 2, 3, None, 4, 5]…
- The minimum is deleted from the min-heap [2, 5, 3, 9, 6, 4, 8] (0-indexed): the last element moves to the root and sifts down, swapping…
- An undirected graph has 6 vertices with degrees 3, 3, 2, 2, 2 and x, and it has 8 edges. What is x?