FastPrepText Justification
Problems/Text Justification

Text Justification

Airbnb logoAirbnb● HardFULLTIMEPHONE SCREEN

Updated Nov 2026

QuestionFunctionExamplesConstraints

Problem statement

Source note: Airbnb asked a frequently reported text justification question in a phone screen for a senior engineer. It came in parts. First, justification into a fixed number of lines. Second, wrapping text into lines of a fixed width. Third, splitting an article into several columns, which the candidate only described.

The report did not give the rules for any part. This problem covers the fixed-width part. We chose the well-known full-justification rules: pack words greedily, spread extra spaces from the left, and left-justify and pad single-word lines and the last line. Words are printable characters without spaces. The limits are up to 300 words of up to 20 characters, with a width up to 100. The fixed-line-count and multi-column parts are not checked.

Our version is about 60% the same as the reported question.

Given an array of words and a width maxWidth, format the text so that every line has exactly maxWidth characters and is fully justified.

  • Pack words greedily: put as many words on a line as fit when separated by single spaces.
  • Spread the extra spaces between the words of a line as evenly as possible. If they do not divide evenly, the gaps on the left get one more space than the gaps on the right.
  • A line with only one word is left-justified: the word, then spaces up to maxWidth.
  • The last line is left-justified: words separated by single spaces, then spaces up to maxWidth.

Return the lines in order.

Function

fullJustify(words: String[], maxWidth: int) → List<String>

Examples

Example 1

words = ["This","is","an","example","of","text","justification."]maxWidth = 16return = ["This    is    an","example  of text","justification.  "]
  • The first line holds This is an (8 letters), so 8 spaces fill 2 gaps: 4 each.
  • The second line holds example of text (13 letters): 3 spaces over 2 gaps, so the left gap gets 2 and the right gap 1.
  • The last line is left-justified and padded on the right.

Example 2

words = ["What","must","be","acknowledgment","shall","be"]maxWidth = 16return = ["What   must   be","acknowledgment  ","shall be        "]
  • acknowledgment is alone on its line (it does not fit with the next word), so it is left-justified and padded: "acknowledgment ".
  • The last line shall be is left-justified even though it has two words.

Example 3

words = ["a"]maxWidth = 1return = ["a"]
  • One word that exactly fills the width.

Constraints

  • 1 <= words.length <= 300
  • 1 <= words[i].length <= 20
  • words[i] consists of printable non-space ASCII characters (letters, digits and symbols).
  • 1 <= maxWidth <= 100
  • words[i].length <= maxWidth

More Airbnb interview questions

  • Read Across Sound TracksPHONE SCREEN · Seen Nov 2026
  • Decode and Store StringsPHONE SCREEN · Seen Oct 2026
  • Print Sentences as TablePHONE SCREEN · ONSITE INTERVIEW · Seen Sep 2026
  • Detonate Bombs with Chain ReactionsPHONE SCREEN · Seen Aug 2026
  • Smallest Common RegionPHONE SCREEN · Seen Aug 2026
  • Longest Chain BookingPHONE SCREEN · Seen Aug 2026
  • Nested List Iterator with RemovePHONE SCREEN · Seen Jul 2026
  • Parse Query StringPHONE SCREEN · Seen May 2026
  • Credit Accounts with Scheduled TransfersOA · Seen Oct 2026
  • Parcel Attribute Store with TTLOA · Seen Oct 2026

Similar questions at other companies

  • Greedy and Beam Sentence DecodingMicrosoft · PHONE SCREEN · ONSITE INTERVIEWMicrosoft interview questions
  • Design In-Memory File SystemSnowflake · PHONE SCREENSnowflake interview questions
  • Text JustificationUber · PHONE SCREENUber interview questions
  • Parse and Query Server LogsKikoff · PHONE SCREENKikoff interview questions
  • Word Wrap with Even JustificationSentry · OA · PHONE SCREENSentry interview questions
  • Search and Format ContactsAdyen · PHONE SCREENAdyen interview questions
  • Subtract Two Large Number StringsStackAdapt · PHONE SCREENStackAdapt interview questions
  • Business Account KYC Verification — Parts 1–5Stripe · PHONE SCREENStripe interview questions
  • Stateful Log Transform and SearchRippling · PHONE SCREEN · ONSITE INTERVIEWRippling interview questions
  • In-Memory Filesystem CommandsPerplexity AI · PHONE SCREEN · ONSITE INTERVIEWPerplexity AI interview questions

Interview reports that mention this question

  • Airbnb Senior SWE Phone Screen Interview Experience: 1 Experience

Airbnb interview experiences

  • Airbnb SWE CodeSignal OA: 19 Experiences
  • Airbnb CodeSignal OA Experience — September 2026
All Airbnb interview questionsSee Airbnb hiring insights
Saved
class Solution {
    public List<String> fullJustify(String[] words, int maxWidth) {
        // Write your code here.
    }
}
Checking account…