algorythms
Dynamic Programming
LC #139Medium

Word Break

Dynamic Programming
AmazonGoogleMetaBloombergMicrosoft

Problem

Determine if a string can be segmented into words from a dictionary.

stringdynamic-programmingtrie

Constraints

  • 1 ≤ s.length ≤ 300
  • 1 ≤ wordDict.length ≤ 1000
  • 1 ≤ wordDict[i].length ≤ 20
  • Lowercase English only; no duplicate words

Example

Inputs = "leetcode", wordDict = ["leet","code"]
Outputtrue
Why

"leetcode" = "leet" + "code". Both words in dictionary

Hints — reveal one at a time