Can the Word Be Split?
L9 Hard Dynamic Programming
Segmenting a string uses the same overlap structure as other DP: whether a prefix is segmentable leads to checks of the next dictionary word.
Given a string s and a dictionary of words wordDict (reusable any number of times), return true if s can be split into a sequence of dictionary words.
Examples
▸ s = "leetcode", wordDict = ["leet", "code"]
→ true
▸ s = "applepenapple", wordDict = ["apple", "pen"]
→ true
▸ s = "catsandog", wordDict = ["cats", "dog", "sand", "and", "cat"]
→ false