Google | Onsite | Word Break III
9015

Given a sentence without spaces s and a dictionary dict, you have to find the way to break the sentence in the minimum number of individual dictionary words. If there're multiple solutions, return any of them.

Example 1:

Input: s = "bedbathandbeyand", dict = ["bed", "bath", "bat", "and", "hand", "bey", "beyand"]
Output: ["bed", "bath", "and", "beyand"] or ["bed", "bat", "hand", "beyand"]

Example 2:

Input: s = "catsandog", dict = ["cats", "dog", "sand", "and", "cat"]
Output: []

Related problems:

Comments (19)