Easy

Quiz

#14 Longest Common Prefix

APPROACH

Determine the longest string that is a leading prefix of every string in the input array. Return an empty string "" if no common prefix exists.

Example 1:

Input: strs = ["flower","flow","flight"]
Output: "fl"

Example 2:

Input: strs = ["dog","racecar","car"]
Output: ""
Explanation: There is no common prefix among the input strings.
1 of 4
1:00

What is the optimal approach for this problem?