FastPrepMinimum Lines for Two Wrapped Text Columns
Problems/Minimum Lines for Two Wrapped Text Columns

Minimum Lines for Two Wrapped Text Columns

Google logoGoogle● MediumNEW GRADONSITE INTERVIEW

Updated Nov 2026

QuestionFunctionExamplesConstraints

Problem statement

Source note: The report gives the follow-up with two texts sharing one width, and the exact width-10 example. We fixed the delimiter, the search for the split, how whitespace is cleaned up, and the result when it is impossible. Our version is about 88% the same as the reported question.

Two space-separated texts must be printed side by side within a page of width maxWidth. The two text fragments on a row are separated by the three-character delimiter | .

On each row, take a consecutive, nonempty group of remaining words from the left text, the right text, or both. Preserve every word and its order, use one space between adjacent words from the same text, and require the two fragment lengths plus three to be at most maxWidth. The separator position may differ between rows.

Return the minimum number of rows needed to consume both texts. Return -1 when some word cannot fit even on a row by itself. Two empty texts use zero rows.

Function

minTwoColumnLines(left: String, right: String, maxWidth: int) → int

Examples

Example 1

left = "I have eaten"right = "I am"maxWidth = 10return = 2

The two rows are I have | I and eaten | am; their separator positions may differ.

Example 2

left = "alpha beta"right = "x y z"maxWidth = 15return = 2

One row pairs alpha with all three right words, and the second row contains beta.

Example 3

left = "longword"right = "x"maxWidth = 10return = -1

The left word needs eight characters plus the three-character separator, exceeding the page width even when the right fragment is empty.

Constraints

  • Each text contains at most 30 words and at most 500 characters.
  • 3 <= maxWidth <= 100.
  • Texts contain lowercase English words separated by one or more ASCII spaces.

More Google Onsite Interview questions

  • Route Pattern MatcherPHONE SCREEN · ONSITE INTERVIEW · Seen Nov 2026
  • Evaluate a Nested Math ExpressionPHONE SCREEN · ONSITE INTERVIEW · Seen Nov 2026
  • Distinct Subset SumsONSITE INTERVIEW · Seen Nov 2026
  • Playlist With No Same Artist in a RowONSITE INTERVIEW · Seen Nov 2026
  • Delete Nodes and Return Forest RootsONSITE INTERVIEW · Seen Nov 2026
  • Dice-Walk Winning ProbabilityPHONE SCREEN · ONSITE INTERVIEW · Seen Nov 2026
  • First and Last Target Position in a Mountain ArrayONSITE INTERVIEW · Seen Nov 2026
  • Lowest Common Ancestor in an N-ary TreePHONE SCREEN · ONSITE INTERVIEW · Seen Nov 2026
  • 0/1 Knapsack with Weight and Volume LimitsONSITE INTERVIEW · Seen Nov 2026
  • Batched Subsequence Word MatchesONSITE INTERVIEW · Seen Nov 2026

Similar questions at other companies

  • Rearrange a String So No Neighbors MatchThe D.E. Shaw Group · ONSITE INTERVIEWThe D.E. Shaw Group interview questions
  • Reorganize a StringAmazon · PHONE SCREEN · ONSITE INTERVIEW
  • Longest-Match Tokenizer with Unknown SymbolsAnthropic · ONSITE INTERVIEWAnthropic interview questions
  • Minimum Nonadjacent Flips for an Alternating Binary StringInfosys · ONSITE INTERVIEWInfosys interview questions
  • Shortest Sequence of Source SubsequencesPinterest · ONSITE INTERVIEWPinterest interview questions
  • Maximize Workday EarningsCitadel · OA · PHONE SCREEN · ONSITE INTERVIEWCitadel interview questions
  • Minimum Removal for Balanced ParenthesesMeta · PHONE SCREEN · ONSITE INTERVIEWMeta interview questions
  • Choose the Next Hidden-Word GuessFlexport · ONSITE INTERVIEWFlexport interview questions
  • Minimum Remove to Make Valid ParenthesesBloomberg LP · PHONE SCREEN · ONSITE INTERVIEWBloomberg LP interview questions
  • Valid Parenthesis StringMotive · PHONE SCREEN · ONSITE INTERVIEWMotive interview questions

Google interview experiences

  • Google interviews · November 2026
  • Google Software Engineer Onsite Questions: 10 Experiences
  • Google OA: What It Tests (2026)
  • Google L4 SWE Phone Screen: 1 Experience
  • Google ML Engineering Manager Onsite: 1 Experience
  • Google Experienced SWE First Round and Onsite: 1 Experience
All Google interview questionsSee Google hiring insights
Saved
class Solution {
    public int minTwoColumnLines(String left, String right, int maxWidth) {
        // Write your code here.
    }
}
Checking account…