algorythms
Arrays & Hashing
LC #14Easy

Longest Common Prefix

Arrays & Hashing

Problem

Write a function to find the longest common prefix string amongst an array of strings.

string

Constraints

  • 1 ≤ strs.length ≤ 200
  • 0 ≤ strs[i].length ≤ 200
  • strs[i] consists of only lower-case English letters.

Example

Inputstrs = ["flower", "flow", "flight"]
Output"fl"
Why

"fl" is the longest string that is a prefix of all inputs.

Hints — reveal one at a time