Number of Lines To Write String
Solve this the way you would in the interview: out loud, on a timer, with an AI interviewer asking follow-ups while you code. You get a scored report at the end.
Practice this as a mock interviewFree to start, no account neededProblem
You are writing the lowercase string s across lines that are each at most 100 pixels wide. The array widths has length 26, and widths[0] is the pixel width of 'a', widths[1] of 'b', and so on.
Write the letters in order. Place each letter on the current line if it still fits within 100 pixels; otherwise start a new line and put the letter there. Letters are never split or reordered.
Return [lines, lastWidth]: the total number of lines used and the width in pixels of the last line.
Examples
Constraints
- widths.length == 26
- 2 <= widths[i] <= 10
- 1 <= s.length <= 1000
- `s` consists of lowercase English letters
What the interviewer grades
A correct solution is one of five scores. The report also grades problem understanding (did you clarify inputs and edge cases before coding), problem solving, communication while you work, code quality, and testing. See a sample report, or read up on the pattern in the lessons.