Dsa
Trie
Medium
Auto-Complete System
Design an auto-complete system using a trie data structure. Given a list of words, when provided with a prefix, output all words that start with that prefix, sorted in lexicographical order. If no words match the prefix, output 'No suggestions available'.
Input:
The first line contains an integer N (1 <= N <= 10000), the number of words in the list.
The next N lines each contain a single word consisting of lowercase letters.
The last line contains the prefix query, a lowercase string (1 <= len <= 20).
Output:
Output all matching words, each on a new line. If no matches are found, output 'No suggestions available'.
Example:
Input:
4
apple
appetizer
banana
apricots
app
Output:
apple
appetizer
apricots
Key concepts
triesearchauto-complete
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