Medium · Dynamic Programming

Sentence Screen Fitting

Given a sentence as a list of words and a screen of rows × cols, return how many times the whole sentence can be written on the screen. Words keep their order, a word is never split across lines, consecutive words on a line are separated by one space, and a new copy continues right after the previous one.

Examples

Example 1

["hello","world"] on 2 × 8

Output: 1×

Example 2

["a","bcd","e"] on 3 × 6

Output: 2×

Rebuild it in the studio

Read every interview problem free. Ten rooms need no account. A token opens a problem in full — Pro never counts.

More Dynamic Programming problems