The TransCompilator

Solved LeetCode program · 314 of 1,000

#0429 · N-ary Tree Level Order Traversal

Medium Breadth-First Search chunk-07.md

Original English source

Keep a shared values holding 1, 3, 2, 4, 5, and 6. Keep a shared nodeparents holding -1, 0, 0, 0, 1, and 1. Keep a shared queue as an empty list of whole numbers. Place 0 into queue. Keep a shared count of 1. Keep a shared nextcount of 0.
To expand from node (a whole number) with candidate (a whole number). If candidate is more than 5, return. If item candidate of nodeparents is node, Place candidate into queue, add 1 to count, add 1 to nextcount. Expand from node with candidate plus 1.

The head is 0. The remaining is 1. The line is empty text.
Repeat while head is less than count.
The node is item head of queue. Add 1 to head. The piece is format whole number item node of values as text. If the length of line is more than 0, Place "," into line. Place piece into line. Expand from node with 0. Subtract 1 from remaining. If remaining is 0, Show line, set line to empty text, set remaining to nextcount, set nextcount to 0.

Open in Playground Browse all 1,000 problems

Expected stdout

1
3,2,4
5,6