LeetCode 139 Word Break - Problem Statement

The problem

Given a string s and a dictionary of words, determine if s can be segmented into space-separated dictionary words.

With s = "leetcode" and wordDict = ["leet","code"]:

  • "leetcode" = "leet" + "code".
  • Both in dictionary. Return true.

With s = "applepenapple" and wordDict = ["apple","pen"]:

  • "applepenapple" = "apple" + "pen" + "apple".
  • Words can be reused. Return true.

With s = "catsandog" and wordDict = ["cats","dog","sand","and","cat"]:

  • No valid segmentation exists. Return false.

Constraints: 11 \le s.length 300\le 300.