Word Wrap Line Count with Whitespace and Newlines
Asked at Google · Coding Questions · Difficulty: Easy · Last asked Feb 1, 2026
A page has a fixed width measured in characters. Given a block of text, lay it out line by line and return how many lines the page needs. Words are packed greedily, explicit newlines always start a new line, and runs of other whitespace count as one gap.
Loading the problem…
More Google interview questions
- LLM conceptual questions
- Implement a Nested Tic-Tac-Toe Game Engine
- ML Fundamentals Deep Dive (AI/ML & MLE Roles)
- ML System Design: Recsys, Chatbot, Image Classifier
- Implement Scaled Dot-Product Attention
- Meeting Rooms: Minimum Rooms to Hold All Meetings