Code Room
CodingMediumcod-g304
Subject TrieLevel Entry–Mid~20 minCommon in Algorithms & data structures interviewsIndustries Software development

Question

Build a trie from the list words (duplicates allowed and counted separately). Then for each query prefix, return how many words in the collection start with that prefix. The empty-string prefix matches every word. Words and prefixes contain only lowercase letters. Return the list of counts in query order.

Implement
trie_prefix_counts(words: list[str], prefixes: list[str]) → list[int]
Examples
in[["apple","app","apricot","banana"],["app","ap","b","xyz",""]]out[2,3,1,0,4]
What a strong answer looks like

State your approach and its time/space complexity out loud before you optimize. Handle the edge cases (empty input, duplicates, overflow), and say why you chose this over the brute force. Green tests are the floor, not the grade.

Vibe coding: describe the solution in plain language (or narrate it) and the coach grades your approach. Generating runnable code from your description is coming next.

Run or narrate your approach, then ask the coach.