FrontendInterviews.dev

Loading problem…

285. Word Break

Medium•
Acceptance: 88.89%
•
🔓3/3 Pro unlocks today

Given a string s and a dictionary of words wordDict, return true if s can be segmented into a space-separated sequence of one or more dictionary words.

Requirements

Implement:

function wordBreak(s, wordDict) {}

Example Usage

wordBreak('leetcode', ['leet', 'code']);
// true

wordBreak('catsandog', ['cats', 'dog', 'sand', 'and', 'cat']);
// false

Constraints

  • 1 <= s.length <= 300
  • 1 <= wordDict.length <= 1000
  • Words can be reused multiple times