Binary Tree Level Order Traversal
Traverse a binary tree level by level, returning nodes grouped by depth.
Input format
The first line contains level-order tokens, where N denotes a null node.
Output format
Print one line per depth level, with values space-separated.
Constraints
- Values fit in a 64-bit signed integer
- Trailing whitespace and a trailing newline are ignored by the judge
Read from stdin, write to stdout. Sample cases below show the exact format.
Sample cases
Example 1
Input
52 55 33 67 77 23 31 94 91 N N 63 75 43 65 30 42 N N 13 12 N N 21 86 44 N N N N N N N 9 20Expected output
52
55 33
67 77 23 31
94 91 63 75 43 65
30 42 13 12 21 86 44
9 20
Example 2
Input
90 5 57 21 32 99 89 34 10 81 85 67 N 3 98 N N 46 26 92 77 N N N N N 82 N N N N N N 33 93Expected output
90
5 57
21 32 99 89
34 10 81 85 67 3 98
46 26 92 77 82
33 93