Search⌘ K
AI Features

Solution: Word Break II

Explore how to solve the Word Break II problem by returning all possible valid sentences from a string using a dictionary. Understand the recursive naive solution and optimize it with dynamic programming through bottom-up tabulation. Learn to build a lookup table to store valid sentence combinations, reduce redundant computations, and analyze the time and space complexity involved.

Statement

You are given a string, s, and an array of strings, wordDict, representing a dictionary. Your task is to add spaces to s to break it up into a sequence of valid words from wordDict. We are required to return an array of all possible sequences of words (sentences). The order in which the sentences are listed is not significant.

Note: The same dictionary word may be reused multiple times in the segmentation.

Constraints:

  • 11 \leq s.length 20\leq 20 ...