profile picture

    Word Break II

    Hard

    Problem Description

    Given a string s and a dictionary of strings wordDict, add spaces in s to construct all possible sentences where each word is in wordDict.

    Return all such possible sentences in any order.

    For this live runner, return sentences in sorted lexicographic order for deterministic checking.

    Examples

    Example 1:

    Input: s = "catsanddog", wordDict = ["cat","cats","and","sand","dog"]
    Output: ["cat sand dog","cats and dog"]
    

    Example 2:

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

    Constraints

    • 1 <= s.length <= 20
    • 1 <= wordDict.length <= 1000
    • 1 <= wordDict[i].length <= 10

    Hint

    Memoized DFS avoids recomputing suffix solutions.

    Solution

    AI Code Assistant

    Test Results

    Run tests to see the overall score, band, and section breakdown.

    Public Tests

    Detailed feedback for visible cases.

    Public test details will appear here after you run your solution.

    Hidden Tests

    Summary only, with no hidden inputs or outputs.

    No hidden test results yet.

    Performance

    Execution timing and pass/fail status.

    No performance results yet.

    AI Interviewer