Data Structures & AlgorithmsModerateCodeforces Div 2 · ICPC regional
A trie keeps a counter at each node, and every word of the list W = ['ab', 'acc', 'aac', 'bcaa', 'cab', 'ab', 'a'] is inserted once per occurrence (so repeated words add to the counter). How many entries of W begin with the prefix 'a'?
- A. 4
- B. 2
- C. 5
- D. 7
Correct answer: C. 5
Counting entries (with repeats) that start with 'a' gives 5. Counting distinct words, substring matches, or suffix matches are different questions.
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 = [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…
- 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…