Data Structures & AlgorithmsHardProduct Company SDE · Amazon OA

Problem: Insert the words "car", "cat", "care", "dog", "do", "dot" into an empty trie (one node per character, root has no letter). How many nodes does the trie have, including the root?

  1. A. 9
  2. B. 19
  3. C. 18
  4. D. 10

Correct answer: D. 10

Shared prefixes share nodes: root + c, a, r, t, e (car/cat/care) + d, o, g, t (do/dog/dot) = 10. Leaving out the root gives 9, giving every character its own node gives 18 (19 with the root).

More Coding Interview Problems questions

Exams that ask this topic