FastPrepText Justification
Problems/Text Justification

Text Justification

Uber logoUber● HardFULLTIMEPHONE SCREEN

Updated Nov 2026

QuestionFunctionExamplesConstraints

Problem statement

Source note: The interview report names the usual text justification task but leaves out the function signature, the exact rules for spreading spaces, and the limits. Those usual details are spelled out below. Our version is about 90% the same as the reported question.

Given an array of words and an integer maxWidth, format the words into lines of exactly maxWidth characters.

  • Pack each line greedily with as many words as fit, counting at least one space between adjacent words.
  • For every non-final line with at least two words, distribute spaces as evenly as possible. When they do not divide evenly, earlier gaps receive one extra space.
  • Left-justify the final line and every single-word line: place one space between words and pad the right side with spaces.

Return the formatted lines in order. Input words contain no spaces, and every word fits within maxWidth.

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 two lines are fully justified to width 16. The final single-word line is padded on the right.

Example 2

words = ["What","must","be","acknowledgment","shall","be"]maxWidth = 16return = ["What   must   be","acknowledgment  ","shall be        "]

The long middle word forms a single-word line, and the final line uses one internal space plus right padding.

Example 3

words = ["a"]maxWidth = 3return = ["a  "]

The only line is the final line, so the word is followed by two padding spaces.

Constraints

  • 1 <= words.length <= 10000
  • 1 <= words[i].length <= maxWidth <= 10000
  • Words contain printable non-space ASCII characters.
  • The total number of word characters is at most 200000.

More Uber Phone Screen questions

  • Worst-Performing Ads by CTR in a Campaign TreePHONE SCREEN · Seen Nov 2026
  • Earliest Time All Users Are ConnectedPHONE SCREEN · ONSITE INTERVIEW · Seen Oct 2026
  • Max Points on a LinePHONE SCREEN · Seen Oct 2026
  • Convex Function MinimizationPHONE SCREEN · Seen Oct 2026
  • Meeting Rooms IIPHONE SCREEN · Seen Oct 2026
  • Merge Meeting IntervalsPHONE SCREEN · Seen Oct 2026
  • Minimum Meeting Rooms with AssignmentsPHONE SCREEN · ONSITE INTERVIEW · Seen Oct 2026
  • Find Robots by Blocker DistancesPHONE SCREEN · Seen Oct 2026
  • Sliding-Window Rate LimiterPHONE SCREEN · Seen Oct 2026
  • Count Connected IslandsPHONE SCREEN · Seen Sep 2026

Similar questions at other companies

  • Greedy and Beam Sentence DecodingMicrosoft · PHONE SCREEN · ONSITE INTERVIEWMicrosoft interview questions
  • Find GPU Capacity and Drain a NodeTogether AI · PHONE SCREEN
  • Word Wrap with Even JustificationSentry · OA · PHONE SCREENSentry interview questions
  • Query Log MatchDatadog · PHONE SCREEN · ONSITE INTERVIEWDatadog interview questions
  • Largest Number Below N from Reusable DigitsByteDance · PHONE SCREENByteDance interview questions
  • Search and Format ContactsAdyen · PHONE SCREENAdyen interview questions
  • Elevator Scheduling SimulationOpenAI · PHONE SCREENOpenAI interview questions
  • Compress Editor Actions into Operational Transform OperationsReplit · OA · PHONE SCREEN · ONSITE INTERVIEW
  • Load/Store Arithmetic InterpreterJane Street · PHONE SCREENJane Street interview questions
  • Match a Variadic Function SignatureConfluent · PHONE SCREENConfluent interview questions
All Uber interview questionsSee Uber hiring insights
Saved
class Solution {
    public List<String> fullJustify(String[] words, int maxWidth) {
      // write your code here
    }
}
Checking account…