The TransCompilator

Solved LeetCode program · 516 of 1,000

#0725 · Split Linked List in Parts

Medium Linked List chunk-11.md

Original English source

Keep a shared values holding 1, 2, and 3. Keep a shared width of 0. Keep a shared spot of 0. Keep a shared line as empty text. The parts is 5. The last is the last position of values. The size is last plus 1. The base is size divided by parts. The extra is size modulo parts.

To pack from start (a whole number) with count (a whole number). Place "[" into line.
For every step from start to start plus count minus 1.
If step is more than start, Place ", " into line. The piece is format whole number item step of values as text. Place piece into line.

For every part from 0 to parts minus 1.
Set width to base. If part is less than extra, add 1 to width. Set line to empty text. Pack from spot with width. Place "]" into line. Increase spot by width. Show line.

Open in Playground Browse all 1,000 problems

Expected stdout

[1]
[2]
[3]
[]
[]