Back to problems

Binary Tree Vertical Order Traversal

Algorithm · Apple · Medium

You are given the root of a binary tree. Each node lives at a coordinate (row, col). The root sits at row 0, column 0. A node's left child moves to (row + 1, col - 1); its right child moves to (row + 1, col + 1). Produce the vertical order traversal of the tree's node values. Group values by their column, from the smallest (leftmost) column to the largest (rightmost). Within a single column, order the values from top to bottom. When two nodes share the same row and the same…

Checking your access…