Prefix frequency queries
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.
0:00 of about 25 min
solution.py
InputExpectedGot
[["apple","app","apply","banana"],["app","ban","cat"]][3,1,0]not run yetsample