Loading...
You are given an array of strings words.
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.
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.
Input: words = ["dog","racecar","car"]
Output: ""
Explanation: The very first characters already disagree, so nothing is shared.
words.length ≤200words[i].length ≤200words[i] consists of lowercase English letters when it is non-emptyClick "Run" to test with sample cases or "Submit" to run all tests.