EvalFrame Technical Mock Interviews & Coding Practice

Word Break

Medium · Dynamic Programming · Algorithm problem · all problems

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. Note that the same word in the dictionary may be reused multiple times in the segmentation. **Examples:** ```typescript wordBreak("leetcode", ["leet", "code"]) // true wordBreak("applepenapple", ["apple", "pen"]) // true wordBreak("catsandog", ["cats", "dog", "sand", "and", "cat"]) // false ```

Solve It in the BrowserPractice Explaining It Out Loud

Optimal Approach

  • Time complexity: O(n^2)
  • Space complexity: O(n)

Nested loops iterate over all substrings of length n, checking hash set in O(1).

Follow-Up Questions Interviewers Ask About Word Break

  • How could you optimize the inner loop of Word Break?
    Only check j where (i - j) is at most the maximum word length in wordDict.

Practice the full problem with execution, tests, and AI code review in the interactive lab — then rehearse explaining your solution in a live voice mock interview.