Dsa
Trie
Warm-up
Simple Autocomplete System
You are tasked with creating a simple autocomplete system using a trie data structure. The system should allow you to insert words and then search for words that start with a given prefix. The input consists of a series of operations:
1. 'INSERT <word>' - Insert a word into the trie.
2. 'SEARCH <prefix>' - Return all words in the trie that start with the given prefix, sorted in alphabetical order.
The input will end after the last operation and you must print the search results for each 'SEARCH' operation.
Example:
INPUT:
INSERT apple
INSERT app
INSERT banana
SEARCH app
SEARCH a
SEARCH b
SEARCH x
OUTPUT:
app
apple
banana
Key concepts
trieautocompletedata-structure
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