140. Word Break II

Practice Word Break II for free on NudgeCode: Hard, Backtracking pattern. Write it in Python or JavaScript, run the tests in your browser, and ask for a hint when you are stuck.

Add spaces to s so that every piece is a word from wordDict, and return every sentence you can build this way. A word may be used any number of times. Return [] if there is none. The sentences can be in any order.

Example

s = "catsanddog", wordDict = ["cat","cats","and","sand","dog"]
->  ["cats and dog","cat sand dog"]

Constraints