Skip to main content
Back to problems
Leetcode
Medium
Strings
Dynamic Programming
Hash Maps
Tries
Google
Amazon
Word Break

Determine whether a string can be segmented into a sequence of dictionary words.

Acceptance 0%
Problem Statement

Word Break

Given a string s and a list of words wordDict, determine whether s can be formed by concatenating one or more words from the dictionary.

You may reuse dictionary words any number of times. The same dictionary word can appear multiple times in the segmentation if needed.

Your task is to return true if such a segmentation exists, otherwise return false.

Input Format

  • A string s
  • An array wordDict of strings representing the dictionary

The exact input representation may vary by platform, but the logical inputs are always the same.

Output Format

Return a boolean value:

  • true if s can be segmented into dictionary words
  • false otherwise

Constraints

  • 1 <= s.length <= 300
  • 1 <= wordDict.length <= 1000
  • Dictionary words are non-empty strings
  • Words may be reused multiple times

These are representative practice constraints, not guaranteed official limits.

Examples
Sample cases returned by the problem API.

Example 1

Input

s = "leetcode"
wordDict = ["leet","code"]

Output

true

Explanation

"leetcode" can be split as "leet" + "code".

Example 2

Input

s = "applepenapple"
wordDict = ["apple","pen"]

Output

true

Explanation

The string can be segmented as "apple" + "pen" + "apple".

Show 1 more example

Example 3

Input

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

Output

false

Explanation

No valid segmentation covers the entire string.

Premium problem context

Unlock deeper context for this problem

Premium adds guided hints, editorial links, similar variants, discussion resources, and concept maps so you can understand why a problem matters, not just solve it once.

Guided hints
Editorial and discussion links
Concept map and variants
Sign in to unlock
Track your progress
Sign in to bookmark this problem, save notes, and manage its revision plan.