words. Call a word *complete* if every non-empty prefix of it (the word itself included) also appears in words. For example, with words = ['b', 'bo', 'box'] the word box is complete: b, bo and box are all in the list.
Return the longest complete word. If several complete words share that length, return the alphabetically smallest one. If there are no complete words, return the empty string.words=['t', 'te', 'tea', 'team', 'teal', 'ten'] → 'teal'
Both team and teal have all their prefixes (t, te, tea) in the list. Both have length 4, and teal is alphabetically smaller.
words=['dog', 'do', 'cat'] → ''
There are no one-letter words, so no word qualifies.
words=['q', 'qu', 'quiz', 'x'] → 'qu'
quiz is missing its prefix qui, so the best answer is qu.
len(words) ≤ 10⁵len(words[i])words=['t', 'te', 'tea', 'team', 'teal', 'ten']
'teal'
Run checks the first 3 tests in your browser. Submit checks all 118 tests on the server, hidden ones included.