words and a line width width. Break the text into lines and justify it so that every line is exactly width characters long.
- Lines are filled greedily: each line takes as many consecutive words as fit with at least one space between neighbouring words.
- Spaces between words are spread as evenly as possible. When they do not divide evenly, the gaps on the left get one more space than the gaps on the right.
- A line holding a single word, and the last line of the text, are left-aligned: words are separated by one space and the rest of the line is padded with spaces on the right.
Return the list of resulting lines.words=['the', 'quick', 'brown', 'fox', 'jumps', 'over', 'it'], width=14 → ['the quick', 'brown fox', 'jumps over it ']
The first line takes "the quick" (9 characters); "brown" no longer fits. The 5 spare spaces all go into the single gap. The second line has three words and 3 spare spaces: the left gap gets 2 extra, the right one gets 1. The last line is left-aligned.
words=['a', 'bb', 'ccc'], width=4 → ['a bb', 'ccc ']
"a bb" is exactly 4 characters. "ccc" is the last line and gets one trailing space.
words=['notebook', 'pen'], width=8 → ['notebook', 'pen ']
Each word sits on its own line; a one-word line is padded on the right.
words[i] contains no spaceswords=['the', 'quick', 'brown', 'fox', 'jumps', 'over', 'it'], width=14
['the quick', 'brown fox', 'jumps over it ']
Run checks the first 3 tests in your browser. Submit checks all 104 tests on the server, hidden ones included.