AO
Back

Two-Column Table: Place the Divider for Minimum Height

Phone ScreenPhone ScreenLast reported November 2025Low Frequency

Problem Overview

One Waymo phone-screen report (November 2025) gives this problem. The candidate solved it with binary search and names one corner case; a reply on the thread works through an example.

Part 1 — Place the column divider

A table has two columns. You know the text in each column and the table's total width, and the divider between the columns can go anywhere. Place it so the table is as short as possible.

Our setup for wrapping: each line of a cell holds as many words as fit, with one space between words, and a cell is as tall as the number of lines its text needs. The table is as tall as its taller column. The reported corner case is a word longer than its cell. On this page such a word does not fit, so that placement is not allowed (the clarifications cover the other reading).

Our setup: widths are counted in characters, the divider takes no width, and the two column widths add up to total_width, each at least 1.

  • column_height(text: str, width: int) -> int returns the number of lines text takes in a cell width characters wide. The tests call it only when every word fits.
  • place_divider(left_text: str, right_text: str, total_width: int) -> tuple[int, int] returns (left_width, height): a left-column width that makes the table shortest, and that height. When several placements tie, any of them is accepted.

Approach Trade-offs

Approaches actually attempted in reports — including ones that lost candidates time. Pick deliberately.
ApproachNotes
Linear scanTry every divider position and wrap both texts each time: O(n W) for n characters and total width W. Simple and correct; binary search cuts it to O(n log W).
Ternary searchPossible, but the height has flat stretches, so ternary search needs careful plateau handling. The crossover binary search is simpler to get right.

Practice

Write your own against 7 test cases, or read the worked solution — approach, complexity, and code that runs.
Did this match your interview?

If you have had this round, tell us how close this page was. It is how we keep the pages accurate.

Waymo · Phone Screen · Reported 1× across candidate reports
Is this helpful?