Data Structures & AlgorithmsHardGATE CS · ICPC regional
Array A = [22, 11, 12, 9, 20, 23, 25, 15, 2]. How many index pairs i < j satisfy (A[i] XOR A[j]) < 21? (A trie with subtree counts answers this in O(n·bits); the answer here is a plain integer.)
- A. 17
- B. 35
- C. 21
- D. 19
Correct answer: D. 19
Walking the trie with subtree counts, only pairs whose XOR is strictly below 21 are added, giving 19. Including equality or swapping to '>' are the mistakes that produce the other options.
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
- 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…
- Points A(6,3), B(8,7), C(3,7), D(9,2), E(3,6), F(0,4) in the plane. The cost of joining two points is the Manhattan distance |x1−x2| +…
- Undirected simple graph on vertices A, B, C, D, E, F, G with edges A–B (1), A–D (1), B–D (1), B–E (1), B–G (1), C–D (1), C–F (1), D–E (1)…
- Connected undirected graph on vertices A, B, C, D, E, F with edges A–E (1), B–D (1), C–E (1), C–F (1), D–E (1), E–F (1) (weights ignored)…
- On an 8 × 8 chessboard with rows and columns numbered 0 to 7, a knight starts at (1, 0) and must reach (2, 5) (as (row, column)). A knight…
- Directed weighted graph on vertices A, B, C, D, E, F with edges listed in this exact order: D→B (2); A→E (7); A→C (3); D→C (-1); B→A (-2)…