← Atlassian Interview Insights

Atlassian·Software Engineer·Onsite - Coding / Algorithms·Intermediate

IntermediatePrefer not to say
Apr 2026

Summary

Atlassian software engineer round with a text justification problem. Pretty implementation-heavy, more about getting all the edge cases right than any clever algorithm.

Questions Asked (1)

Q1

Given an array of words and a max line width, format the words into fully justified lines where each line is exactly maxWidth characters. Extra spaces are distributed evenly between words, with left gaps getting more if it doesn't divide evenly. The last line is left-justified with trailing spaces.

Algorithms & Data StructuresTechnical Trade-offs
Author's notes

Took me a while to get all the cases sorted out.

Create a free account to read the full note

AI HintsAI Generated

Suggested Approach

First, clarify the problem constraints and edge cases, then outline a greedy line-packing algorithm that builds lines word by word. For each line except the last, compute the number of spaces needed and distribute them as evenly as possible, giving extra spaces to the leftmost gaps. Finally, handle the last line separately by left-justifying and padding with trailing spaces.

Pro tip: Mention that you would test with edge cases like a single word per line, a word longer than maxWidth (if allowed), and lines that exactly fit without extra spaces. This shows attention to detail and robustness.

1. Clarify Requirements and Edge Cases

Ask about constraints: Can words exceed maxWidth? Should we assume at least one word per line? How to handle empty input? Confirm that spaces are distributed with left gaps getting more when uneven.

2. Design Greedy Line Packing

Iterate through words, adding as many as possible to the current line without exceeding maxWidth (considering at least one space between words). Once the next word doesn't fit, finalize the line.

3. Justify Non-Last Lines

For each line except the last, calculate total spaces needed = maxWidth - sum of word lengths. Distribute spaces evenly among gaps: base spaces = totalSpaces / (numWords - 1), remainder = totalSpaces % (numWords - 1). Add one extra space to the first 'remainder' gaps.

4. Handle Last Line and Single-Word Lines

For the last line, left-justify words with a single space between them and pad with trailing spaces to maxWidth. For a line with only one word (non-last), left-justify and pad with spaces to maxWidth.

5. Analyze Complexity and Trade-offs

Discuss time complexity O(n) where n is total characters, and space O(maxWidth) per line. Mention alternative approaches like dynamic programming for optimal line breaking (if cost function considered), but note greedy is standard for this problem.

Key Points to Mention

  • Greedy algorithm for line packing: add words until the next doesn't fit.
  • Space distribution formula: base spaces = totalSpaces / gaps, remainder = totalSpaces % gaps, add extra to leftmost gaps.
  • Special handling for last line: left-justified with single spaces between words, padded with trailing spaces.
  • Edge cases: single word per line, word longer than maxWidth (if allowed), empty input, exact fit.
  • Time and space complexity: O(n) time, O(maxWidth) space per line.
  • Testing strategy: unit tests for uneven distribution, last line, and boundary conditions.

AI-generated suggestions, not part of the candidate's original notes. May be inaccurate — verify before relying on them.