HARDasked at 34 companies

Text Justification

A hard-tier problem at 48% community acceptance, tagged with Array, String, Simulation. Reported in interviews at Airbnb and 33 others.

Founder's read

Text Justification is a hard problem that appears in interviews at Airbnb, Notion, MongoDB, Capital One, and 29 other companies. The acceptance rate sits at 48%, meaning half the candidates who attempt it don't solve it cleanly. The problem looks deceptively simple: take an array of words and a max width, then format lines so each word fits and spacing is distributed evenly. But the spacing logic trips people up, especially the last line edge case. This is exactly the kind of problem where you know the concept but blank on the implementation details during a live assessment. If you hit this in your OA and can't nail the distribution algorithm, StealthCoder surfaces a working solution in seconds, invisible to the proctor.

Companies asking
34
Difficulty
HARD
Acceptance
48%

Companies that ask "Text Justification"

If this hits your live OA

Text Justification is the kind of problem that decides whether you pass. StealthCoder reads the problem on screen and surfaces a working solution in under 2 seconds. Invisible to screen share. The proctor sees nothing. Built because the OA filter rejects engineers who'd pass the on-site. That's a broken filter. This is the workaround.

Get StealthCoder
What this means

The core trick is treating this as a simulation, not a clever algorithm. You iterate through words, greedily pack as many as fit on each line, then handle spacing. Most candidates nail the greedy packing but fumble the spacing distribution: you need to calculate total space, divide it among gaps, handle remainders, and account for the last line being left-justified. The obvious approach of just joining words with spaces fails immediately. Where people crash is forgetting that the last line is special, or miscounting gaps (n words need n-1 gaps), or not distributing extra spaces from left to right when gaps can't be equal. This is pure Array and String manipulation with Simulation logic, not dynamic programming or graph tricks. If you haven't drilled this exact problem before, the spacing edge cases will burn time. StealthCoder is your hedge here: you get the working code instantly and move on.

Pattern tags

The honest play

You know the problem. Make sure you actually pass it.

Text Justification recycles across companies for a reason. It's hard-tier, and most candidates blank under the timer. StealthCoder is the hedge: an AI overlay invisible during screen share. It reads the problem and surfaces a working solution in under 2 seconds. Built because the OA filter rejects engineers who'd pass the on-site. That's a broken filter. This is the workaround. Works on HackerRank, CodeSignal, CoderPad, and Karat.

Text Justification interview FAQ

How hard is Text Justification really?+

It's marked HARD and has a 48% acceptance rate, so expect real friction. The greedy packing is straightforward, but the spacing distribution logic is tedious and error-prone. You'll likely solve it eventually, but the details slow most candidates down. It's implementation-heavy, not conceptually deep.

Is this still asked at big tech companies?+

Yes. Airbnb, MongoDB, and Capital One have all reported asking it. It's not trendy like graph problems, but it's stable in the rotation. Companies like it because it filters for attention to detail and clean code, not just algorithm knowledge.

What's the trick I'm missing?+

There's no secret algorithm here. The trick is treating it as a simulation: greedily pack words line by line, then for each line except the last, distribute spaces left to right, putting extra spaces in the leftmost gaps first. The last line is just left-justified with single spaces. That's it.

How does this relate to Array and String topics?+

You're iterating through a word array, building new strings, and manipulating spacing within strings. No fancy data structures, no sorting or searching. It's pure iteration and string construction, which is why it's classified as Array, String, and Simulation.

Will I get partial credit if my spacing is slightly off?+

Probably not. Online assessments test exact output matching. One space off in distribution or a missing space on the last line fails the test case. That's why edge cases hurt here. You need to code defensively and test against examples with varying word lengths and max widths.

Want the actual problem statement? View "Text Justification" on LeetCode →

Frequency and company-tag data sourced from public community-maintained interview-report repos. Problem, description, and trademark © LeetCode. StealthCoder is not affiliated with LeetCode.