Tap here to switch tabs
Problem
Submissions

Problem: Number of Lines To Write String

med
30 min
Try to solve the Number of Lines To Write String problem.

Statement

You are given an integer array widths of length 2626 and a string s. The array widths indicates the width of each lowercase English letter, where widths[0] is the width of 'a', widths[1] is the width of 'b', and so on up to widths[25] for 'z'.

You start writing the characters of s line by line from left to right. Each line has a maximum width capacity of 100100 units. When adding a character to the current line, if its width would cause the total width of the line to exceed 100100 units, the entire character must be placed at the beginning of a new line.

Return an array of two integers where the first integer represents the total number of lines used, and the second integer represents the width used on the final line.

Constraints:

  • widths.length =26= 26

  • 2≤2 \leq widths[i] ≤10\leq 10

  • 1≤1 \leq s.length ≤1000\leq 1000

  • s contains only lowercase English letters.

⋮
Tap here to switch tabs
Problem
Submissions

Problem: Number of Lines To Write String

med
30 min
Try to solve the Number of Lines To Write String problem.

Statement

You are given an integer array widths of length 2626 and a string s. The array widths indicates the width of each lowercase English letter, where widths[0] is the width of 'a', widths[1] is the width of 'b', and so on up to widths[25] for 'z'.

You start writing the characters of s line by line from left to right. Each line has a maximum width capacity of 100100 units. When adding a character to the current line, if its width would cause the total width of the line to exceed 100100 units, the entire character must be placed at the beginning of a new line.

Return an array of two integers where the first integer represents the total number of lines used, and the second integer represents the width used on the final line.

Constraints:

  • widths.length =26= 26

  • 2≤2 \leq widths[i] ≤10\leq 10

  • 1≤1 \leq s.length ≤1000\leq 1000

  • s contains only lowercase English letters.