Dsa
Trie
Medium
Shortest Unique Prefix
Your task is to find the shortest unique prefix for each word in a list. A prefix is unique if no other word in the list has the same prefix. Implement this using a Trie data structure. The input consists of an integer n followed by n words. Your output should be the shortest unique prefix for each word in the order they were given.
Example:
Input:
3
apple
appetite
banana
Output:
ap
ap
b
Key concepts
trieprefixunique
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