Dsa
Trie
Easy
Search Autocomplete
You are building a search autocomplete feature for a search engine. You need to implement a Trie data structure to facilitate efficient storage and search for a list of strings. Furthermore, you need to provide a method to return all the strings that start with a given prefix. The program should read from standard input:
- The first line will contain an integer n (1 <= n <= 1000), the number of strings to insert into the Trie.
- The next n lines will each contain one string (1 <= length of each string <= 1000) composed of lowercase alphabetic characters.
- The last line will contain a prefix, a string composed of lowercase alphabetic characters.
Your task is to implement the Trie and output all strings in sorted order that start with the given prefix.
Example input:
5
apple
appetizer
application
bat
ball
app
Example output:
appetizer
apple
application
Key concepts
trieautocompletesearch
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