text and a list of words words. You may cross out any letters of text; the remaining letters are read in their original order.
Find the longest word in words that can be obtained from text this way. If several fitting words share the maximum length, return the alphabetically smallest one. If no word fits, return the empty string.text='planetarium', words=['plum', 'planet', 'train', 'pear'] → 'planet'
Crossing letters out of planetarium gives plum, planet and pear; train is impossible, since no a follows the r. The longest is planet.
text='bread', words=['bed', 'red', 'bad'] → 'bad'
All three words of length 3 fit, and bad comes first alphabetically.
text='abc', words=['cab', 'd'] → ''
Letters cannot be reordered, so cab is out, and there is no d in the text. The answer is the empty string.
len(text) ≤ 1000len(words) ≤ 1000len(words[i]) ≤ 1000text and words[i] consist of lowercase English letters onlytext='planetarium', words=['plum', 'planet', 'train', 'pear']
'planet'
Run checks the first 3 tests in your browser. Submit checks all 96 tests on the server, hidden ones included.