Data Structures & AlgorithmsModerateCodeforces Div 2 · ICPC regional
A trie keeps a counter at each node, and every word of the list W = ['ab', 'cc', 'ba', 'ca', 'ac', 'ba', 'cba', 'bba'] is inserted once per occurrence (so repeated words add to the counter). How many entries of W begin with the prefix 'b'?
- A. 5
- B. 3
- C. 1
- D. 2
Correct answer: B. 3
Counting entries (with repeats) that start with 'b' gives 3. 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
- Connected undirected graph on vertices A, B, C, D, E, F, G with edges A–D (1), A–E (1), A–F (1), B–E (1), B–F (1), C–D (1), D–F (1), D–G…
- Connected undirected weighted graph on vertices A, B, C, D, E, F with edges A–B (1), A–C (14), A–F (12), B–D (12), C–D (8), C–E (1), E–F…
- Directed acyclic graph on vertices A, B, C, D, E, F, G (every edge goes from a smaller to a larger letter) with weighted edges A→E (8)…
- Complete undirected graph on vertices A to F with symmetric edge weights given row by row (row i, column j = weight of edge between…
- Directed weighted graph on vertices A, B, C, D, E with edges listed in this exact order: C→A (3); E→C (7); B→C (-2); B→D (6); A→B (5); C→E…
- Undirected graph on vertices A, B, C, D, E, F, G with edges A–D (1), A–E (1), A–G (1), B–C (1), B–F (1), B–G (1), D–F (1), D–G (1), E–G…