Data Structures & AlgorithmsHardICPC regional · GATE CS top band
Array A = [30, 20, 28, 25, 2, 19, 15, 7, 11]. 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.)
- A. 28
- B. 35
- C. 9
- D. 27
Correct answer: D. 27
Walking the trie with subtree counts, only pairs whose XOR is strictly below 25 are added, giving 27. 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
- Connected undirected graph on vertices A, B, C, D, E, F, G, H with edges A–F (1), A–G (1), B–C (1), B–E (1), C–E (1), D–E (1), E–H (1)…
- Array A = [11, 19, 21, 15, 20] (all values below 32). What is the maximum of A[i] XOR A[j] over all index pairs with 0 ≤ i < j < 5?
- Undirected simple graph on vertices A, B, C, D, E, F, G with edges A–B (1), A–C (1), A–D (1), A–E (1), C–E (1), C–F (1), C–G (1), D–F (1)…
- A chain of 5 matrices M1 to M5 has dimensions given by the sequence p = [11, 8, 3, 12, 16, 9], where Mi has size p[i−1] × p[i]…
- Undirected graph on vertices A, B, C, D, E, F with weighted edges A–B (4), A–C (7), A–E (3), B–C (6), B–E (4), B–F (2), C–D (7), C–F (2)…
- Undirected weighted graph on vertices A, B, C, D, E with edges A–D (1), B–D (2), B–E (1), C–D (1), C–E (2), D–E (3). An edge is CRITICAL…