Data Structures & AlgorithmsHardCodeforces Div 2 · ICPC regional
Array A = [6, 24, 27, 0, 7, 23, 30, 19]. 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. 21
- B. 27
- C. 22
- D. 7
Correct answer: A. 21
Walking the trie with subtree counts, only pairs whose XOR is strictly below 25 are added, giving 21. 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
- Tree with vertices 0 to 9, root 0, edges 0–1, 1–2, 1–3, 1–4, 3–5, 1–6, 2–7, 5–8, 4–9 (parent–child). Vertex weights (vertex:weight) 0:16…
- Points A(4,3), B(7,5), C(8,9), D(6,6), E(4,6) in the plane. The cost of joining two points is the Manhattan distance |x1−x2| + |y1−y2|…
- A trie keeps a counter at each node, and every word of the list W = ['bb', 'bba', 'aabc', 'ac', 'aba', 'bbc', 'aab', 'ac'] is inserted…
- Directed graph on vertices A, B, C, D, E, F with edges E→F, E→A, C→D, D→C, D→B, B→C, A→C, A→D, B→D (no weights). What is the number of…
- A binary tree with distinct letters has preorder CHEGDBFA and inorder HECFBADG. What is its postorder traversal (left, right, root)…
- Directed graph on vertices A, B, C, D, E, F, G with edges G→E, A→D, F→A, G→F, C→E, B→E, A→B, B→G, E→G, A→C (no weights). What is the…