Data Structures & AlgorithmsHardGATE CS · Codeforces Div 2
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 this in O(n·bits); the answer here is a plain integer.)
- A. 26
- B. 14
- C. 23
- D. 13
Correct answer: D. 13
Walking the trie with subtree counts, only pairs whose XOR is strictly below 13 are added, giving 13. 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
- 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)…
- Connected undirected graph on vertices A, B, C, D, E, F, G, H with edges A–D (1), B–F (1), B–G (1), B–H (1), C–H (1), D–G (1), E–H (1)…