Level Order Traversal
Easyjavapythonccppjavascript
Given a binary tree in level-order form, print its nodes level by level from top to bottom, one level per line.
Input Format
The first line contains an integer M, the number of level-order tokens. The second line contains M space-separated tokens (integers or null). It is blank when M is 0.
Output Format
For each level from the root downward, print the values on that level separated by single spaces, one level per line. Print nothing for an empty tree.
Example 1
Input
7 3 9 20 null null 15 7
Output
3 9 20 15 7
Explanation: Nodes are grouped by their depth.
- 0 <= number of nodes <= 5000
- -1000000000 <= node value <= 1000000000