Code RoomPrefix word count
MediumPrep Room Coding #875

Prefix word count

CodingAlgorithms & data structuresEntry–Mid~20 min

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.

0:00 of about 20 min
InputExpectedGot
[["apple","app","apricot","banana"],["app","ap","b","xyz",""]][2,3,1,0,4]not run yetsample