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?

  1. The cell: whether the first i letters can be split.
  2. The recurrence: some earlier split point j works, and s[j:i] is a word.
  3. The base: the empty prefix can be split.
  4. The order: left to right.

With a longest word of LL letters, only the last LL split points can matter. So it's O(nL)O(nL) checks, each a slice of at most LL 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.