Easy · Strings

Longest common prefix

Given an array of ASCII strings strs, return the longest string that is a prefix of every string in strs, or the empty string if they share no common prefix.

Examples

Example 1

["flower","flow","flight"]

Output: "fl"

Example 2

["dog","racecar","car"]

Output: "" (no common prefix)

Rebuild it in the studio

Open every published interview problem, solution, scene, and memory room free, with no account.

More Strings problems