FastPrepWord Break
Problems/Word Break

Word Break

Moveworks logoMoveworks● MediumFULLTIMEONSITE INTERVIEW
QuestionFunctionExamplesConstraints

Problem statement

Source note: The reported task identifies this standard algorithmic exercise. The executable interface, bounds, deterministic tie rules, and examples are the documented practice contract.

Given a string s and an array of distinct dictionary words wordDict, return true if s can be split into a sequence of one or more dictionary words.

A dictionary word may be reused any number of times.

Function

wordBreak(s: String, wordDict: List<String>) → boolean

Examples

Example 1

s = "prepcode"wordDict = ["prep","code"]return = true

The string splits as prep + code.

Example 2

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

The word apple is reused in apple + pen + apple.

Example 3

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

No sequence of dictionary words covers the entire string.

Constraints

  • 1 <= s.length <= 300.
  • 1 <= wordDict.length <= 1000.
  • 1 <= wordDict[i].length <= 20.
  • s and every dictionary word contain only lowercase English letters.
  • All dictionary words are distinct.

More Moveworks problems

  • Underline Shortest Unique SubstringsPHONE SCREEN · Seen Oct 2026
  • Minimum Moves to Sort ArrayOA · Seen Jul 2024
  • Number of Balanced StringsOA · Seen Jul 2024
All Moveworks interview questionsSee Moveworks hiring insights
Saved
class Solution {
    public boolean wordBreak(String s, List<String> wordDict) {
      // write your code here
    }
}
Checking account…