Document Line Wrap
Asked at Google
Reported by the problem's creator, not verified
You are given the text of a document as a string text and a page width width in characters. The text holds words separated by spaces and "\n" characters.
Examples
Example 1
Input: text =
Hello world Foo bar baz qux, width =10Output:
4Explanation:
Hello worldis 11 characters, too wide for one row, so it wraps to two rows.Foo bar baz quxfitsFoo barand thenbaz qux, two more rows. Total 4.Example 2
Input: text =
a b, width =5Output:
4Explanation: The text has four lines:
a, two empty lines andb. Each line takes one row, including the empty ones.
Import your own questions
Paste a question you were asked and get a full problem: statement, tests and a checked solution.