Question bank › Trie
Dsa Trie Easy

Unique Prefixes

You are tasked with finding unique prefixes for a list of words. A unique prefix for a word is a prefix that is not shared with any other word in the list. Write a program that reads a list of words from standard input and outputs the unique prefixes for each word. If there are no unique prefixes for a word, output an empty string for that word. 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. Output format: - Output N lines, each containing the unique prefix for the corresponding word. Example: Input: 4 apple ape bat ball Output: ap b

Key concepts

triestringsprefix

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
Part of InterviewLab's verified interview question bank. We show the prompt and concepts to practise with — never a copy-paste solution.