Code Room
CodingMediumcod-g057
Subject TrieLevel Mid–Senior~25 minCommon in Algorithms & data structures interviewsIndustries Software development

Question

Given a list of lowercase words `words` (duplicates possible) and a list of `queries`, for each query return how many words in `words` start with that query as a prefix. Build a structure once and answer all queries efficiently. Return a list of counts aligned with `queries`. `0 <= len(words) <= 20000`, total characters `<= 200000`.

Implement
prefix_counts(words: list[str], queries: list[str]) → list[int]
Examples
in[["apple","app","apply","banana"],["app","ban","cat"]]out[3,1,0]
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.