Dsa
Trie
Warm-up
The Smallest Suggestion
Given a dictionary of N words and a search prefix, find the alphabetically first word in the dictionary that starts with that prefix. If the prefix itself is a word in the dictionary, it is the answer.
Input Format:
1. An integer N.
2. N dictionary words.
3. A query prefix.
Output Format:
The alphabetically first matching word, or 'NONE' if no matches exist.
Example:
Input:
4
apple
apply
apricot
apt
ap
Output:
apple
Key concepts
trielexicographicalsearch
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