Word Break with One Reconstruction
Problem statement
Insert spaces into text so every token belongs to words. Return a valid sentence using the fewest tokens. If several use the same number, return the lexicographically smallest full sentence. Return the empty string when no segmentation exists.
Function
wordBreakSentence(text: String, words: String[]) → StringExamples
Example 1
text = "code"words = ["c","d","co","e","x"]return = "co d e"co, d, and e reconstruct the text.
Constraints
0 <= text.length <= 1000.- Dictionary words are nonempty lowercase strings.