Dsa
Strings
Easy
Longest Prefix Match
Given a list of strings, find the longest common prefix string amongst them. If there is no common prefix, return an empty string.
Input Format:
- The first line contains an integer n, the number of strings.
- The next n lines each contain one string.
Output Format:
- A single line that represents the longest common prefix.
Example:
Input:
3
aeroplanes
aeronautics
aerodynamics
Output:
aero
Key concepts
stringssearchingprefix
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