Longest Common Prefix - Coding Interview Problem

Last modified: April 7, 2023

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