Dsa
Trie
Easy
Prefix Frequency Count
You are given a list of words and a series of queries. For each query, you need to find out how many words start with the same prefix as the query. Implement a program that constructs a trie from the list of words and serves the prefix frequency queries. Input consists of the first line containing an integer n, followed by n words, and then an integer q followed by q queries. Output the number of words that match each query prefix.
Example Input:
5
apple
app
banana
band
bandana
3
app
ban
a
Example Output:
2
2
0
Key concepts
triestring manipulationcounting
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