← 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"]))
- A.3 2
- B.2 2
- C.2 1
- 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 →