Google Interview Problem #3: Line Count with Word Wrap & Optimal Two-Column Width – VO support

Given an English-language text and the width of a page, find how many lines the text would take on that page.

Given a text that you’d like to place into a two-column table on a fixed-width page, find the best column width that minimizes the overall table height.

Subproblem 1 (line count): Given page width, compute number of lines under word-wrapping with no hyphenation. Greedy pack words; start a new line when next word doesn’t fit. Runs in O(n).

Subproblem 2 (two-column optimum): For a fixed page width, choose equal column width to minimize total height. For a width w, wrap to get total lines L(w); two-column height is ceil(L(w)/2). Since H(w) is non-increasing with w, the optimal choice is the largest feasible w satisfying layout constraints (2*w + gutter ≤ pageWidth). If widths are integral pixels, do binary search or simple sweep.

The VOprep team has long accompanied candidates through various major company OAs and VOs, including OpenAI, Google, Amazon, Citadel, SIG, providing real-time voice assistance, remote practice, and interview pacing reminders to help you stay smooth during critical moments. If you are preparing for Stripe or similar engineering-focused companies, you can check out our customized support plans—from coding interviews to system design, we offer full guidance to help you succeed.

END
 0