A binary tree is given in array form: index 0 is the root, and the children of index i sit at 2i+1 and 2i+2. The token null marks a missing node.
Input
- Line 1: n, the number of tokens (
1 ≤ n ≤ 1000)
- Line 2: n tokens, each an integer or
null
Output
One line per depth level, values separated by single spaces, top level first.
Hint
Breadth-first search with a queue. Process the queue one level at a time: take its current length, pop exactly that many nodes, then push their children.
Read from standard input and write to standard output. 5 test cases in total (3 hidden). Tests for this language run inside your browser.