Dsa
Trie
Medium
Prefix Count Query
Implement a Prefix Counter that allows counting how many words in a list start with a given prefix.
Input:
- The first line contains an integer n, the number of words.
- The next n lines contain one word each (1 <= |word| <= 100).
- The last line contains an integer m, the number of prefix queries.
- The next m lines each contain one prefix to query (1 <= |prefix| <= 100).
Output:
- Print the count of words that start with each prefix query on a new line.
Example:
Input:
4
apple
banana
appetizer
apricot
3
app
ba
c
Output:
3
1
0
Key concepts
triecountprefix
Practise this out loud — free
Start a mock interview on THIS exact question — a voice AI interviewer opens with it, pushes back like a real onsite, then hands you an instant scorecard.
🎙 Practise this question now