Skip to content
C

Vertical Order Traversal

Hardjavapythonccppjavascript

Group the nodes of a binary tree by their horizontal distance from the root (root at distance 0, each left step -1, each right step +1). Within a column, list nodes in breadth-first order.

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).

Output Format

Print one line per column, from leftmost to rightmost, values separated by single spaces.

Input (stdin)

Output

Run your code to see output here...