Explanation
Word Break is a Medium interview problem tagged [Hash Table, String, Dynamic Programming]. The winning approach is typically **DP**.
#139
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.
Example 1
Input: s = "leetcode", wordDict = ["leet","code"]
Output: true
Segment as "leet code".
Example 2
Input: s = "applepenapple", wordDict = ["apple","pen"]
Output: true
Reuse apple.
Example 3
Input: s = "catsandog", wordDict = ["cats","dog","sand","and","cat"]
Output: false
Cannot segment fully.
Word Break is a Medium interview problem tagged [Hash Table, String, Dynamic Programming]. The winning approach is typically **DP**.
Overlapping subproblems are solved once and reused.
Define dp state → write transition → fill base cases → iterate in dependency order.
Pattern-level skeleton only — not this problem’s exact answer. Adapt it to the statement.
Time: O(n)
Space: O(n)
Before coding, restate the problem, name the pattern (DP), and write the invariant or DP state in one sentence.
Got it?
Mark #139 Word Break as understood when the pattern clicks.