Longest Common Prefix
Find the longest common prefix string among an array of strings.
Input format
The first line contains N. The second line contains N lowercase words separated by spaces.
Output format
Print the longest common prefix of all words, or -1 if there is none.
Constraints
- Values fit in a 64-bit signed integer
- Trailing whitespace and a trailing newline are ignored by the judge
Read from stdin, write to stdout. Sample cases below show the exact format.
Sample cases
Example 1
Input
3
flower flow flightExpected output
flExample 2
Input
3
dog racecar carExpected output
-1