Binary Tree Level Order Traversal

MediumTrees
Next
TreeBFSQueue

Print the nodes of a binary tree level by level, from left to right, one level per line. Build the tree from the level-order input yourself, then solve the problem.

Input

A single line giving the tree in level order, with the word null for a missing child (for example 3 9 20 null null 15 7).

Output

One line per level, with that level's values separated by spaces.

Constraints

1 <= number of nodes <= 2000

Example 1
Input
3 9 20 null null 15 7
Output
3
9 20
15 7

Levels: 3 / 9 20 / 15 7.

Hints

Binary Tree Level Order Traversal - Medium Trees Problem | Skill Shiksha