FastPrepWord Break with One Reconstruction

Word Break with One Reconstruction

Bloomberg LP logoBloomberg LP● MediumNEW GRADPHONE SCREEN
Learn

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[]) → String

Examples

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.

More Bloomberg LP problems

See Bloomberg LP hiring insights
public String wordBreakSentence(String text, String[] words) {
  // Write your code here.
}
text"code"
words["c","d","co","e","x"]
expected"co d e"
Checking account…