Data Structures & AlgorithmsModerateCodeforces Div 2 · ICPC regional
A trie keeps a counter at each node, and every word of the list W = ['acb', 'c', 'bcb', 'c', 'bc', 'a', 'aac'] is inserted once per occurrence (so repeated words add to the counter). How many entries of W begin with the prefix 'c'?
- A. 2
- B. 4
- C. 6
- D. 1
Correct answer: A. 2
Counting entries (with repeats) that start with 'c' gives 2. 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
- On an 6 × 6 chessboard with rows and columns numbered 0 to 5, a knight starts at (3, 5) and must reach (5, 0) (as (row, column)). A knight…
- Dictionary D = {bem, cle, gcc, icd, imb, lbg, lcp, lri, ois, opg, scc, scp} (all words have 3 letters). Starting from the word 'lcd', a…
- Directed weighted graph on vertices A, B, C, D, E with edges E→C (-3); A→D (-4); A→B (-2); D→B (0); B→C (-2); A→E (-1); E→D (0); B→E (-4)…
- Array A = [5, 6, 5, 4, 3, 8, 4, 6] (indices 0 to 7). Count the non-empty subsets of positions (each position used at most once, subsets…
- 2 × 3 sliding puzzle with tiles 1 to 5 and one blank (shown as ). Current board: 2 4 / 1 5 3. Goal board: 1 2 3 / 4 5 . A move slides a…
- Connected undirected graph on vertices A, B, C, D, E, F with edges A–C (1), A–F (1), B–D (1), C–D (1), C–F (1), D–E (1), D–F (1) (weights…