Question bank › Trie
Dsa Trie Easy

Longest Unique Prefix

You are required to find the longest prefix amongst a list of words where no part of the prefix is repeated in any other word. Write a program that takes a list of words and returns the longest unique prefix. A unique prefix is defined as a prefix that is not present in the start of any other word in the list. If no unique prefix exists, return "No unique prefix.". Input Format: - First line contains an integer N, the number of words (1 ≤ N ≤ 1000). - The next N lines each contain a single word consisting of lowercase English letters (a-z). Output Format: - Print the longest unique prefix if it exists, otherwise print "No unique prefix.". Example Input: 4 flower flow flight flour Example Output: fl

Key concepts

triestring-analysis

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