Data Structures & AlgorithmsModerateCodeforces Div 2 · ICPC regional

A trie keeps a counter at each node, and every word of the list W = ['a', 'c', 'a', 'a', 'cac', 'caa', 'bc', 'bcb'] is inserted once per occurrence (so repeated words add to the counter). How many entries of W begin with the prefix 'a'?

  1. A. 4
  2. B. 3
  3. C. 5
  4. D. 1

Correct answer: B. 3

Counting entries (with repeats) that start with 'a' gives 3. Counting distinct words, substring matches, or suffix matches are different questions.

More Trees, Graphs, Recursion and Dynamic Programming questions

Exams that ask this topic