text with no spaces and a vocabulary vocabulary, a list of words.
Insert spaces into text so that every resulting piece is a word from the vocabulary. A word may be used any number of times, and some words may not be used at all.
Return every sentence that can be formed this way, in any order. Words in a sentence are separated by a single space. If there is no way, return an empty list.text='sunflowerseed', vocabulary=['sun', 'flower', 'sunflower', 'seed', 'flowers', 'eed'] → ['sun flower seed', 'sun flowers eed', 'sunflower seed']
Three splits work: "sun flower seed", "sunflower seed" and "sun flowers eed".
text='abab', vocabulary=['ab'] → ['ab ab']
The same word may be used more than once.
text='planet', vocabulary=['plan', 'net'] → []
After "plan" the rest is "et", which is not in the vocabulary, so there are no splits.
text.length ≤ 100vocabulary.length ≤ 1000vocabulary[i].length ≤ 20text and vocabulary[i] consist of lowercase English letters onlytext='sunflowerseed', vocabulary=['sun', 'flower', 'sunflower', 'seed', 'flowers', 'eed']
['sun flower seed', 'sun flowers eed', 'sunflower seed']
Run checks the first 3 tests in your browser. Submit checks all 62 tests on the server, hidden ones included.