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

30:00

Longest Common Prefix
easy
Topics
Companies

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

Example 1:
Input: ["flower","flow","flight"]
Output: fl
Constraints:
  • 1strs.length2001 \leq \text{strs.length} \leq 200

  • 0strs[i].length2000 \leq \text{strs}[i].\text{length} \leq 200

  • strs[i] consists of only lowercase English letters.

Input
arr =["flower","flow","flight"]

Start: "flower"

String 1
f0l1o2w3e4r5
String 2
f0l1o2w3
String 3
f0l1i2g3h4t5
Variables
VariableValue
prefixflower
DepthFunction Call
Stack empty
0/5