text with no spaces and vocabulary, a list of distinct words.
Decide whether text can be cut into one or more consecutive pieces so that every piece equals some word from the vocabulary. A word may be used any number of times, and some words may go unused.
Return True if such a split exists and False otherwise.text='sunflowerseed', vocabulary=['sunflow', 'ers', 'sun', 'flower', 'seed'] → True
Starting with "sunflow" leads nowhere: after "ers" the leftover "eed" cannot be split. But "sun" + "flower" + "seed" works.
text='aaab', vocabulary=['a', 'aa'] → False
No vocabulary word contains the letter b, so the string cannot be split.
text='abab', vocabulary=['ab'] → True
The same word may be used more than once: "ab" + "ab".
text.length ≤ 300vocabulary.length ≤ 1000vocabulary[i].length ≤ 20text and vocabulary[i] consist of lowercase English letters onlyvocabulary are distincttext='sunflowerseed', vocabulary=['sunflow', 'ers', 'sun', 'flower', 'seed']
True
Run checks the first 3 tests in your browser. Submit checks all 72 tests on the server, hidden ones included.