Solved LeetCode program · 921 of 1,000
#1282 · Group the People Given the Group Size They Belong To
Original English source
Keep a shared sizes holding 3, 3, 3, 3, 3, 1, and 3. Keep a shared people of 7. Keep a shared bucket as a list of 7 zeros. Keep a shared line as empty text. Keep a shared count of 0.
To gather from target (a whole number). Set count to 0.
For every person from 0 to people minus 1.
If item person of sizes is target, Set item count of bucket to person, add 1 to count.
To render from start (a whole number) with target (a whole number). Set line to empty text.
For every offset from 0 to target minus 1.
The spot is start plus offset. If offset is more than 0, Place "," into line. Place format whole number item spot of bucket as text into line.
For every target from 1 to people.
Gather from target.
If count is more than 0.
The start is 0.
Repeat while start is less than count.
Render from start with target. Show line. Add target to start.
Expected stdout
5 0,1,2 3,4,6