Trains the technique from
LeetCode 68Text JustificationThis is an original problem, written from a brief that listed the technique, the difficulty, the topics, the function shape and the input bounds — none of that problem's wording, examples, hints or editorials. The link is there so you can map your practice onto the standard set.
Same function shape, different story and different numbers.
A platform notice board prints one announcement at a time on a character cell display that is width cells across. The announcement arrives already chopped into pieces as tokens, in the order they must appear. No token contains a blank, and no token is longer than width.
Lay the tokens out row by row and return the rows as a list of strings, each string exactly width characters long, built by these rules.
width, so widen the blank runs between its tokens. Every gap gets the same number of blanks where that is possible. If the blanks do not divide evenly over the gaps, the surplus goes to the gaps nearest the left edge, one extra blank each, until the surplus is used up. So the leftmost gap is never narrower than a gap to its right.width. That holds even if the final row happens to carry several tokens.Example 1
Row one holds two tokens and one gap, so both surplus blanks land in it. Row two carries a single token padded on the right. The final row fills the display exactly, so no padding is needed.
Example 2
Row one has three blanks to spread over two gaps, so the left gap takes two and the right gap takes one. The final row is a lone token padded to the right edge.
Example 3
The first token is as wide as the display, so nothing can share its row and it needs no padding at all.
The editor is preloaded with this. It matches the parent problem's shape, so a solution that works here transfers to a judge unchanged.
def render_board(tokens: list[str], width: int) -> list[str]:public List<String> renderBoard(String[] tokens, int width)See the step-by-step animation, the intuition, and clean code in every language — free, no credit card.