Columns of a Tree
You are given the root of a binary tree. Draw it on squared paper: the root goes in row 0, column 0. A left child goes one row down and one column to the left of its parent, a right child one row down and one column to the right. Two nodes can land on the same square.
Return the values column by column, from the leftmost column to the rightmost. Inside a column, go from the top row down. Nodes on the same square are listed by value, smallest first.
Trees appear in the tests in level order, with null for a missing child, like [3,9,20,null,null,15,7]. Each node is a TreeNode with .val, .left and .right; the class is already defined for you.
Example 1
Column 0 holds the root 8 and, two rows down on one square, the nodes 6 and 4. Of those two the smaller value comes first.
Example 2
The left child is one column to the left of the root.
Example 3
The node 3 hangs to the right under 2, which brings it back into the column of the root.
Constraints
1 <= number of nodes <= 400 <= node.val <= 1000
Write it in your browser, against the clock. The model solution, stepped through line by line, comes after.