Given a paragraph represented as a string of words, a terminal can only write two words per line. Calculate the total number of lines needed to print the entire paragraph.
Words in the paragraph are separated by single spaces. If the total number of words is odd, the last line will contain only one word.
Function Signature
def count_lines(paragraph: str) -> int:
Rules
-
A word is a maximal run of non-space characters.
-
Words are printed in their original order, two per line, so every line except possibly the last holds exactly two words.
Constraints
-
1 <= len(paragraph) <= 10^4
-
The paragraph contains only lowercase English letters and spaces.
-
Words are separated by single spaces.
-
There are no leading or trailing spaces.
Examples
Input: paragraph = "hello world foo bar baz"
Output: 3
There are 5 words. Line 1 is "hello world", line 2 is "foo bar" and line 3 is "baz", so 3 lines are needed.
Input: paragraph = "the quick brown fox"
Output: 2
There are 4 words. Line 1 is "the quick" and line 2 is "brown fox".
Input: paragraph = "a"
Output: 1
A single word still needs one line of its own.