Dsa
Trie
Medium
Common Prefix Finder
Create a program to find the longest common prefix among a list of strings. Use a trie to efficiently search for the common prefix. If there is no common prefix, return 'No common prefix'.
Input:
The first line contains an integer N (1 <= N <= 10000), the number of strings.
The next N lines each contain a single string (1 <= length <= 100).
Output:
Output the longest common prefix, or 'No common prefix' if none exists.
Example:
Input:
4
flower
flow
flight
flour
Output:
fl
Key concepts
triecommon prefixstring comparison
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