37/40
Part 7 of 7 · Follow-upsLearn and do
Word Break is the same four things on a one-dimensional table
Word Break is on Netflix's tag list (1 source): can a string be split into dictionary words?
- The cell: whether the first
iletters can be split. - The recurrence: some earlier split point
jworks, ands[j:i]is a word. - The base: the empty prefix can be split.
- The order: left to right.
With a longest word of letters, only the last split points can matter. So it's checks, each a slice of at most letters and a set lookup.
In the editor, write can_break(s, words) on a one-dimensional table. It cuts two strings of park words.