Tap here to switch tabs
Problem
Submissions

Problem: Sentence Screen Fitting

med
30 min
Try to solve the Sentence Screen Fitting problem.

Statement

Given an array of strings sentence and two integers rows and cols representing the dimensions of a screen, return the total number of times the complete sentence can be fitted on the screen.

The words must be formatted according to the following rules:

  • Words must appear on the screen in their original order.

  • Consecutive words on the same row must be separated by a single space.

  • A word cannot be split across multiple rows.

  • If a word does not fit in the remaining columns of the current row, it must start on the next row.

  • After placing the last word of sentence, the sentence can immediately repeat starting with its first word.

Constraints:

  • 1≤1 \le sentence.length ≤100\le 100

  • 1≤1 \le sentence[i].length ≤10\le 10

  • sentence[i] consists of lowercase English letters.

  • 1≤1 \le rows, cols ≤2imes104\le 2 imes 10^4

⋮
Tap here to switch tabs
Problem
Submissions

Problem: Sentence Screen Fitting

med
30 min
Try to solve the Sentence Screen Fitting problem.

Statement

Given an array of strings sentence and two integers rows and cols representing the dimensions of a screen, return the total number of times the complete sentence can be fitted on the screen.

The words must be formatted according to the following rules:

  • Words must appear on the screen in their original order.

  • Consecutive words on the same row must be separated by a single space.

  • A word cannot be split across multiple rows.

  • If a word does not fit in the remaining columns of the current row, it must start on the next row.

  • After placing the last word of sentence, the sentence can immediately repeat starting with its first word.

Constraints:

  • 1≤1 \le sentence.length ≤100\le 100

  • 1≤1 \le sentence[i].length ≤10\le 10

  • sentence[i] consists of lowercase English letters.

  • 1≤1 \le rows, cols ≤2imes104\le 2 imes 10^4