Find the longest prefix shared by every string in an array.
Given an array of strings, return the longest prefix that appears at the start of every string.
If there is no common prefix, return an empty string.
A prefix is a substring that starts at the beginning of a string.
strs.strs[i] contains lowercase or mixed-case text depending on the platform variant.strs.1 <= strs.lengthExample 1
Input
strs = ["flower", "flow", "flight"]
Output
"fl"
Explanation
All three strings start with fl, but the next character differs.
Example 2
Input
strs = ["dog", "racecar", "car"]
Output
""
Explanation
There is no character sequence that appears at the start of every string.
Premium problem context
Premium adds guided hints, editorial links, similar variants, discussion resources, and concept maps so you can understand why a problem matters, not just solve it once.