Dsa
Trie
Easy
Autocomplete Suggestions
You have a list of words and want to build an autocomplete system. Given a prefix, the program should return all words from the list that start with that prefix. Write a program that reads a list of words and a prefix from standard input, and outputs all suggestions starting with that prefix.
Input format:
- The first line contains an integer N, the number of words.
- The next N lines each contain a single word consisting of lowercase letters only.
- The last line contains the prefix string.
Output format:
- Output all words that start with the given prefix, each on a new line.
Example:
Input:
4
hello
hi
hey
how
h
Output:
hi
hey
how
Key concepts
trieautocompletestrings
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