🎙 Free live masterclass · Sun, 29 Nov, 7:00 pm IST · Java Full Stack roadmap Register free →
Skills101
← Quiz: Design Search Autocomplete: all 10 questions

Quiz: Design Search Autocomplete · Question 5 of 10

What does this print? (code)

What does this print?

trie = {}
for w in ["cat", "car", "dog"]:
    node = trie
    for ch in w:
        node = node.setdefault(ch, {})
print(len(trie), len(trie["c"]["a"]))
  1. A.3 2
  2. B.2 2
  3. C.2 1
  4. D.1 2
Answer & explanation

Correct answer: 2 2

The root has children c and d; the node for "ca" has children t and r.

Can you get the rest right without peeking?

Take the timed Quiz: Design Search Autocomplete quiz free. Pass it to earn XP and count towards your certificate.

Start the quiz →