Skip to content

Practice Longest Common Prefix

Read the task, work through the examples, and check your approach against the constraints. Use the original LeetCode task for coding and submissions.

Easy#14
LeetCode Problem

Longest Common Prefix

Problem Statement

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 "".

Source: Longest Common Prefix on LeetCode. Use the original task for its coding environment and submissions.

Examples

# Example 1

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

# Example 2

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

Constraints

1 <= strs.length <= 200
0 <= strs[i].length <= 200
strs[i] consists of only lowercase English letters if it is non-empty.

Related LeetCode Problems

Practice more problems similar to Longest Common Prefix.

Review your practice with PhantomCodeAI

After trying the problem yourself, use the app to discuss your approach, complexity, and edge cases.