← All problems
Word Break
Given a string s and a dictionary of words, determine whether s can be segmented into a space-separated sequence of one or more dictionary words. The same word may be reused.
Complexity
Time O(n^2), Space O(n)
Common pitfalls
- Greedy longest-match (fails)
- Not memoizing the recursion (exponential)
Your solution
Log in to save your code and track progress.