Return the longest string that is a prefix of every word in words. If the words share no prefix at all, return the empty string "".
A prefix is a leading run of characters, so "fl" is a prefix of "flower" and "" is a prefix of every string. Note that words may contain empty strings, and any array containing one shares no prefix.
Examples
Example 1
Input: words = ["flower","flow","flight"]
Output: "fl"
Explanation: All three begin f, l. The third character disagrees: "flower" and "flow" have o while "flight" has i, so the shared prefix stops at length 2.
Example 2
Input: words = ["dog","racecar","car"]
Output: ""
Explanation: The very first characters already disagree, so nothing is shared.
Constraints
1≤words.length≤200
0≤words[i].length≤200
words[i] consists of lowercase English letters when it is non-empty
Loading editor...
Log in to run your code. Your draft is saved in this browser.Log inSign up