Binary Tree Vertical Order Traversal
Given the root of a binary tree, return its vertical order traversal: group node values by their column (root is column 0, a left child is column-1, a right child is column+1), list columns left to right, and within a column order nodes top to bottom, with ties on the same row kept in left-to-right order.
Open official problem prompt ↗Bucket every node by its horizontal column and output the columns left to right, each read top to bottom.
Sorting mail into vertical pigeonholes: the column decides which slot, and because you process floor by floor, higher letters land in each slot before lower ones.
- Input
- root = [3,9,20,null,null,15,7]
- Output
- [[9],[3,15],[20],[7]]
- Why
- Columns are 9 at -1; 3 and 15 at 0 (3 is higher); 20 at +1; 7 at +2, read left to right.
The number of nodes is in the range [0, 100]-100 <= Node.val <= 100