Interview question: Longest Common Prefix

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.

Example 1

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

Example 1

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

Example 3

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

Test

Results