Code
Loading editor...
Tap Analyze to see visualization
Click Analyze to visualize
See step-by-step execution, variables, and output
Variables
Run code to see variables
Output
Console output will appear here
Click Analyze to visualize
See step-by-step execution, variables, and output
Run code to see variables
Console output will appear here
Greedily pack words into each line. For non-final multi-word lines, distribute spaces as evenly as possible and place extras on the left. Left-justify final or single-word lines.
Taking the maximum words per line preserves minimal remaining width, then deterministic space distribution satisfies exact width constraints.
Updated Feb 2026