Word Break II
Given a string s and a dictionary wordDict, return all possible sentences where s is segmented into a space-separated sequence of dictionary words. Words may be reused. Return the sentences in any order.
Open official problem prompt ↗Produce every full segmentation of s into dictionary words as readable sentences.
Listing all the different routes through a city where each road segment is a dictionary word - you enumerate paths, caching the routes from each intersection you have already explored.
- Input
- s = "catsanddog", wordDict = ["cat", "cats", "and", "sand", "dog"]
- Output
- ["cats and dog", "cat sand dog"]
- Why
- Both "cats|and|dog" and "cat|sand|dog" tile the string using dictionary words.
1 <= s.length <= 201 <= wordDict.length <= 10001 <= wordDict[i].length <= 10s and wordDict[i] consist of only lowercase English lettersAll dictionary words are uniqueThe answer may contain up to 10^4 sentences