Back to problems

Reconstruct a Sentence from a Dictionary (Word Break Variant)

Algorithm · Microsoft · Medium

You are given a string whose spaces have all been removed, along with a dictionary of words. Put spaces back into the string so that it becomes a sentence made up only of words from the dictionary. Return the restored sentence. If the string cannot be split into dictionary words, return None. This is a word-break variant: the expected output is the actual segmentation itself, not merely whether one exists, and the no-solution case must return None. Interview Notes In this…

Loading the rest of the question…