673. Sentence Screen Fitting

Given a rows x cols screen and a sentence represented as a list of strings, return the number of times the given sentence can be fitted on the screen.

The order of words in the sentence must remain unchanged, and a word cannot be split into two lines. A single space must separate two consecutive words in a line.

Example 1:

Input: sentence = ["hello","world"], rows = 2, cols = 8

Output: 1

Explanation:

hello---

world---

The character '-' signifies an empty space on the screen.

Example 2:

Input: sentence = ["a", "bcd", "e"], rows = 3, cols = 6

Output: 2

Explanation:

a-bcd- 

e-a---

bcd-e-

The character '-' signifies an empty space on the screen.

Now Your Turn!

Pick the correct output for the given input

Input : sentence = ["a", "bcd", "e"] , rows = 3 , cols = 6

Still unsure what the problem is asking ?

Let’s go through a few more examples, step by step, to make it clearer.

Constraints:

  • 1 <= sentence.length <= 100
  • 1 <= sentence[i].length <= 10
  • sentence[i] consists of lowercase English letters.
  • 1 <= rows, cols <= 2 * 104

Hints

Frequently Occurring Doubts

Interview Follow-up Questions

Fun Facts

0
class Solution {
public:
int wordsTyping(vector<string>& sentence, int rows, int cols) {
// Your code goes here
}
};
Test Case

Input:

Columns
Rows
Sentence