Longest Common Prefix
Easyjavapythonccppjavascript
Given a list of strings, find the longest prefix shared by every string. If there is no common prefix, the answer is the empty string.
Input Format
The first line contains an integer K, the number of strings. Each of the next K lines contains one string with no spaces.
Output Format
Print the longest common prefix. If it is empty, print an empty line.
Example 1
Input
3 flower flow flight
Output
fl
Explanation: All three strings start with fl but differ at the next character.
- 1 <= K <= 1000
- 1 <= length of each string <= 200
- Strings consist of lowercase English letters.