{ "cells": [ { "cell_type": "markdown", "metadata": {}, "source": [ "This notebook was prepared by [Donne Martin](https://github.com/donnemartin). Source and license info is on [GitHub](https://github.com/donnemartin/interactive-coding-challenges)." ] }, { "cell_type": "markdown", "metadata": {}, "source": [ "# Challenge Notebook" ] }, { "cell_type": "markdown", "metadata": {}, "source": [ "## Problem: Find how many times a sentence can fit on a screen.\n", "\n", "See the [LeetCode](https://leetcode.com/problems/sentence-screen-fitting/) problem page.\n", "\n", "
```\n",
"Given a rows x cols screen and a sentence represented by a list of non-empty words, find how many times the given sentence can be fitted on the screen.\n",
"\n",
"Note:\n",
"\n",
"A word cannot be split into two lines.\n",
"The order of words in the sentence must remain unchanged.\n",
"Two consecutive words in a line must be separated by a single space.\n",
"Total words in the sentence won't exceed 100.\n",
"Length of each word is greater than 0 and won't exceed 10.\n",
"1 ≤ rows, cols ≤ 20,000.\n",
"Example 1:\n",
"\n",
"Input:\n",
"rows = 2, cols = 8, sentence = [\"hello\", \"world\"]\n",
"\n",
"Output: \n",
"1\n",
"\n",
"Explanation:\n",
"hello---\n",
"world---\n",
"\n",
"The character '-' signifies an empty space on the screen.\n",
"Example 2:\n",
"\n",
"Input:\n",
"rows = 3, cols = 6, sentence = [\"a\", \"bcd\", \"e\"]\n",
"\n",
"Output: \n",
"2\n",
"\n",
"Explanation:\n",
"a-bcd- \n",
"e-a---\n",
"bcd-e-\n",
"\n",
"The character '-' signifies an empty space on the screen.\n",
"Example 3:\n",
"\n",
"Input:\n",
"rows = 4, cols = 5, sentence = [\"I\", \"had\", \"apple\", \"pie\"]\n",
"\n",
"Output: \n",
"1\n",
"\n",
"Explanation:\n",