314. Binary Tree Vertical Order Traversal
Problem
Return the vertical order traversal of a binary tree as columns of node values from left to right.
Given the root of a binary tree, perform a vertical order traversal. Nodes are grouped by their horizontal distance from the root. A node's column is determined by the sum of left moves (-1) and right moves (+1) from the root.
Return a list of lists where each inner list contains node values from top to bottom for each column, ordered from leftmost column to rightmost.
Examples
Input: [1]
Output: [[1]]
Input: [1,2]
Output: [[2],[1]]
Hints
Use BFS and track the column index for each node.
Group nodes by their column index.
BFS already visits each column top to bottom; nodes sharing a row and column keep their left-to-right BFS order, which is not value order.
314. Binary Tree Vertical Order Traversal
Return the vertical order traversal of a binary tree as columns of node values from left to right.