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 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

Mid September, 2024

Google

Google

Junior

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

Comments

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