CodeOath
← All problems

Word Break

Medium
dynamic-programmingstrings

Given a string s and a dictionary of strings wordDict, return true if s can be segmented into a space-separated sequence of one or more dictionary words. The same dictionary word may be reused multiple times.

Example:

Input: s = "pineapple", wordDict = ["pine","apple"]
Output: true
Explanation: "pineapple" can be segmented as "pine apple".

Constraints:

  • 1 <= s.length <= 300
  • 1 <= wordDict.length <= 1000
  • 1 <= wordDict[i].length <= 20