Fixed-Width Text Formatter

Asked at AirbnbOnsite

Reported by the problem's creator, not verified

You are laying text out for a display with a fixed character width. Write format_text, which returns the layout as a list of strings.

Examples

  1. Example 1

    Input: text = this is a article, width = 10

    Output: ["this is a ","article "]

    Explanation: this is a takes 9 characters, and adding article would make 17, so the line is closed and padded with one space. article is 7 characters and is padded with 3 spaces.

Import your own questions
Paste a question you were asked and get a full problem: statement, tests and a checked solution.
Import a question

Code

Loading editor…

Ln 1, Col 1

Start an attempt to use Coach.