dsa · easy

Longest Common Prefix

String

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

Arguments

**Example 1:** `` Input: strs = ["flower","flow","flight"] Output: "fl" ``

Constraints

1 <= strs.length <= 200 Hidden tests include near-max size for this bound; a slower-than-intended solution TLEs.

Examples

Example 1

Input:
["flower","flow","flight"]

Expected:
fl

Example 2

Input:
["dog","racecar","car"]

Expected:

Open in the Dojo editor