Word Break
Pentland Search receives queries with the spaces stripped out — sandstone might be one word or two. Before showing results, the system has to decide whether the query can be read as a run of words from its dictionary, using the whole query and leaving no leftover letters. A dictionary word may be used more than once, since a query can legitimately repeat one. If the query cannot be read that way, it is passed to a spell checker instead.
Task: Print whether the first line can be read as a run of dictionary words, using every letter.
Input
Two lines. The first holds the query: between 1 and 300 lowercase letters, no spaces. The second holds the dictionary: between 1 and 1000 words separated by single spaces, each made of lowercase letters.
Output
One line holding exactly Yes or No, with that capitalisation. Yes means the whole query can be cut into pieces, one after another with nothing skipped and nothing left over, where every piece is a dictionary word. A word may be reused as often as needed. Any other reading is No.
Example:
Input:
sandstone
sand stone
Output:
Yes
Sign in to solve this problem
Reading problems is free for everyone — solving them (Run, Submit, and tracking what you've solved) needs an account.
Sign in