Vertical Column Report Of A Tree
Render a binary tree as vertical columns (like an org chart printed top-to-bottom by column). Group node values by their horizontal column; within a column order by row, and break ties at the same row by value.
Problem
Given the root of a binary tree, return its vertical order traversal. The root is at column 0; a left child is column-1, a right child is column+1. Output columns left to right; within a column, order by row top to bottom; nodes sharing the same row and column are ordered by ascending value.
Input
The root of a binary tree.
Output
A list of lists — node values grouped by column, left to right.
Constraints
- 1 ≤ node count ≤ 1000
- 0 ≤ node value ≤ 1000
Examples
Example 1
Input
[3,9,20,null,null,15,7]
Output
[[9],[3,15],[20],[7]]
Columns -1,0,1,2 hold 9 | 3,15 | 20 | 7.
Example 2
Input
[1,2,3,4,5,6,7]
Output
[[4],[2],[1,5,6],[3],[7]]
At column 0, nodes 5 and 6 share row 2; ordered by value.