Search
⌘K

Leetcode 806. Number of Lines To Write String

Given an array widths mapping each lowercase letter to its pixel width and a string s, pack characters sequentially into lines with a maximum width of 100 pixels and return [number_of_lines, width_of_last_line]. This is solved by greedily scanning s, accumulating letter widths and starting a new line whenever adding the next letter would exceed 100.

Asked at:

Google

Google


Question Timeline

See when this question was last asked and where, including any notes left by other candidates.

Mid March, 2026

Google

Google

Mid-level

a mix of 806 and text justification. "You work at a publisher house and are going to print the number of lines of a large file given it's input path, count the number of lines in the file." No examples were provided. As a sub-problem you have to first suggest that the page width would be a parameter, then return number of lines.

Mid October, 2024

Google

Google

Mid-level

Given a sequence of words as a single string, place them into lines of specified width. Return the number of lines needed.

Early October, 2024

Google

Google

Junior

Given a string of characters and a specified horizontal page width, determine how many lines the string would occupy while maintaining spaces in the output

Your account is free and you can post anonymously if you choose.