36/40
Part 7 of 7 · Follow-upsLearn and do

When is greedy enough? When the best-looking step can never rule out the best answer

You can show greedy is safe by swapping any other choice for the greedy one, and losing nothing. Text Justification is on Airbnb LeetCode tag lists from two different compilations (3 sources) and in a prep guide to Anthropic's interviews (1 source). As asked, it is greedy: each line takes as many words as fit, then the spaces are spread.

Change the goal to the fewest squared spaces at the ends of lines, with the last line free. Here is then go up a red trail at width 10:

Predict

Greedy fills each line as full as it can and pays 25. What does a table over the line breaks pay?

Pick an answer above to see the rest