Back to the 100
Problem 006Arrays & Hashing
Easy

Longest Common Prefix

006

Given an array of strings, return the longest prefix shared by every string. Return an empty string if none exists.

EXAMPLES

Example 1
Input
{
  "strs": [
    "flower",
    "flow",
    "flight"
  ]
}

Output
"fl"

FUNCTION SHAPE

strs: stringArraystring
00:00
4 local tests readyRun with ⌘/Ctrl + Enter. Your code stays in this browser.

Runs solve(...) locally in a browser worker. SWE Playbook does not submit your code. Only run code you trust; Python code may access the network.