Dsa
Trie
Easy
Word Search Suggestions
You are tasked with designing an autocomplete system for a list of words. You need to implement a Trie data structure to manage the words and support a function that retrieves all words that start with a given prefix.
Input Format:
The first line contains an integer n (1 ≤ n ≤ 1000), the number of words.
The next n lines each contain a single word (1 ≤ length of word ≤ 100).
The last line contains a string prefix to search (1 ≤ length of prefix ≤ 100).
Output Format:
Print all words that start with the given prefix in lexicographical order, one word per line.
Example:
Input:
4
apple
ape
bat
ball
ap
Output:
ape
apple
Key concepts
trieautocompletestring manipulation
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