1
var wordBreak = function (s, wordDict) {
2
const n = s.length;
3
const result = [];
4

5
const findValidSentences = (
6
currentString = "",
7
remainingString = s,
8
currentIndex = 0
9
) => {
10
if (currentIndex === remainingString.length) {
11
if (wordDict.includes(remainingString)) {
12
result.push(`${currentString} ${remainingString}`.trim());
13
}
14
return result;
15
}
16

17
const newWord = remainingString.slice(0, currentIndex);
18
if (wordDict.includes(newWord)) {
19
const newCurrentString = `${currentString} ${newWord}`;
20
const newRemainingString = remainingString.slice(currentIndex);
21
findValidSentences(newCurrentString, newRemainingString, 0);
22
}
23

24
return findValidSentences(currentString, remainingString, currentIndex + 1);
25
};
26

27
return findValidSentences();
28
};

0

WPM •0 •0

100%

ACC •0 •0

0s

TIME •0