You are given an array of strings, arr[]. Identify and return the longest common prefix shared among all the strings in the array.
Example 1
Input: arr = ["apple", "ape", "april"]
Output: "ap"
Explanation: The longest common prefix among the strings is "ap".
Example 2
Input: arr = ["cat", "dog", "fish"]
Output: ""
Explanation: There is no common prefix among the strings.
Approach, complexity and clean code in every language. Sign in to unlock the editorial.
Your submissions, results and runtime history live here. Sign in to start your streak.
flower flow flight
fl
dog racecar car
""
a
a