Medium · Trees

Binary Tree Vertical Order Traversal

Given the root of a binary tree, return its node values grouped by vertical column (root at column 0, a left child one column left, a right child one column right), columns ordered left to right; within a column, values go top to bottom, and nodes sharing a row and column appear left to right. An empty tree returns [].

Examples

Example 1

[3,9,20,·,·,15,7]

Output: [9] [3,15] [20] [7]

Example 2

[1,2,3,4,5,6,7]

Output: [4] [2] [1,5,6] [3] [7]

Rebuild it in the studio

Read every interview problem free. Ten rooms need no account. A token opens a problem in full — Pro never counts.

More Trees problems