146. Vertical Slices
hardtreebfssorting
Place the root at column 0; a left child is one column to the left and one row down, a right child one column right and one row down. Return the columns from left to right. Within a column, order nodes by row, then by value for nodes sharing a row and column.
The tree arrives as a TreeNode (val, left, right). Tests write trees in level order, with null for missing children.
Example 1
Inputroot = [3,9,20,null,null,15,7]
Output[[9],[3,15],[20],[7]]
Example 2
Inputroot = [1,2,3,4,5,6,7]
Output[[4],[2],[1,5,6],[3],[7]]
Example 3
Inputroot = [1,2,3,4,6,5,7]
Output[[4],[2],[1,5,6],[3],[7]]
Constraints
- 1 ≤ nodes ≤ 1000