← 返回 uber 的题目列表Word Break
类型:qbank
Onsite coding prompt equivalent to Word Break. Given a string `s` and dictionary `wordDict`, determine whether `s` can be segmented into a sequence of dictionary words.
Requirements
Input: string s and list / set wordDict.
Return true if s can be formed by concatenating one or more dictionary words.
Dictionary words may be reused.
Return false when no full segmentation covers the entire string.
Notes
Clarify whether the interviewer wants a boolean only or all valid segmentations; the reported prompt asked for the boolean decision.
A recursive brute force is easy to write but can revisit the same suffix many times.
Preparation
Practice bottom-up DP over prefix length and top-down memoization over start index.
Write tests for overlapping words, repeated use of the same word, and a long string with no valid final segment.