Longest Common Prefix

Write a function to find the longest common prefix string amongst an array of strings. If no common prefix, return empty string.

Input Format

First line integer n, followed by n words.

Output Format

The longest common prefix string.

Constraints

  • 1 <= n <= 1000; total chars <= 10^5.

Examples

Example 1:

Input:

strs = ["flower","flow","flight"]

Output:

fl

Example 2:

Input:

strs = ["dog","racecar","car"]

Output:

Loading...
Longest Common Prefix - Strings DSA Problem