Input: s = "leetcode", wordDict = ["leet", "code"]Output: trueExplanation: Return true because "leetcode" can be segmented as "leet code".
Input: s = "applepenapple", wordDict = ["apple", "pen"]Output: trueExplanation: Return true because "applepenapple" can be segmented as "apple pen apple". Note that you are allowed to reuse a dictionary word.
Input: s = "catsandog", wordDict = ["cats", "dog", "sand", "and", "cat"]Output: false
def wordBreak(self, s: str, wordDict: List[str]) -> bool: length = len(s) res =  * (length+1) res = 1 for j in range(1,length+1): for i in range(j): if s[i:j] in wordDict and res[i]: print(s[i:j]) res[j] = 1 return res[length]
All the after-result depend on the previous calculation.
For res[j] to be True, res[i] and string s[i:j] in wordDict hace to be true.
Basic case is res = 1 and goes through the string and the substring.
Time complexity is O(n^2) and space complexity is N