Loading...
Loading...
Loading...
A label printer has a list of allowed words. A label is a string with no spaces. Print YES if the label can be cut into one or more allowed words, using words any number of times, and NO if it cannot.
Example 1
Input
apple pen applepenapple
Output
YES
apple + pen + apple.
Example 2
Input
cats dog sand and cat catsandog
Output
NO
Try the problem first. Open one hint at a time.
dp[i] is True when some word ends at i and the part before it is True.
Put the words in a set and look at the last word length at most 20 only.
Write your Python code, run it on the examples and submit it to hidden tests.
Solve in the editor