Number of Lines To Write String Problem

Number of Lines To Write String Problem — ExecCode Easy DSA Practice

Solve the Number of Lines To Write String problem on ExecCode. Free online easy DSA practice in Arrays - Logic Building. Write and run code in Java, C++, Python — no signup required to run.

Problem description

Description You are given a string s of lowercase English letters and an array widths denoting how many pixels wide each lowercase English letter is. Your task is to compute the required answer and return an array result of length 2 where:. Specifically, widths[0] is the width of 'a', widths[1] is the width of 'b', and so on. You are trying to write s across several lines, where each line is no longer than 100 pixels. Starting at the beginning of s, write as many letters on the first line such that the total width does not exceed 100 pixels. Then, from where you stopped in s, continue writing as many letters as you can on the second line.

Examples

Input {"widths": [10, 10, 10, 10, 10, 10, 10, 10, 10, 10, 10, 10, 10, 10, 10, 10, 10, 10, 10, 10, 10, 10, 10, 10, 10, 10], "s": "abcdefghijklmnopqrstuvwxyz"}; Output [3, 60]. Input {"widths": [4, 10, 10, 10, 10, 10, 10, 10, 10, 10, 10, 10, 10, 10, 10, 10, 10, 10, 10, 10, 10, 10, 10, 10, 10, 10], "s": "bbbcccdddaaa"}; Output [2, 4]

Constraints

widths.length == 26 2 <= widths[i] <= 10 1 <= s.length <= 1000 s contains only lowercase English letters.

Practice Number of Lines To Write String free on ExecCode. Browse DSA problems, topic map, and placement guides.