Problems

Longest Common Prefix

easy
easy
strings

Given an array of strings, find the longest common prefix string amongst them. If there is no common prefix, return an empty string "".

Note:

All given inputs are in lowercase letters a-z.

Examples

Example 1

Input: strs = ["start","stair","stop"]
Output: "st"

Example 1

Input: strs = ["cat","dog","mouse"]
Output: ""

Example 3

Input: strs = ["very long string","very long string","very long string"]
Output: "very long string"

Partial prefix

Input: strs = ["flower","flow","flight"]
Output: "fl"

No common prefix

Input: strs = ["dog","racecar","car"]
Output: ""

Single string

Input: strs = ["alone"]
Output: "alone"

Empty list

Input: strs = []
Output: ""

Shortest string is prefix

Input: strs = ["prefix","pre","prefixed"]
Output: "pre"

Contains empty string

Input: strs = ["abc","","abcd"]
Output: ""

Single character match

Input: strs = ["a","a","a"]
Output: "a"

Diverging after two chars

Input: strs = ["apple","apply","april"]
Output: "ap"

Running will execute all 11 cases.