Binary Tree Vertical Order Traversal

Medium

Company Tags

You are given the root node of a binary tree, return the vertical order traversal of its nodes' values.

For the vertical order traversal, list the nodes column by column starting from the leftmost column and moving to the right.

Within each column, the nodes should be listed in the order they appear from the top of the tree to the bottom.

If two nodes are located at the same row and column, the node that appears to the left should come before the other.

Example 1:

Input: root = [1,2,3,4,5,6,7]

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

Example 2:

Input: root = [1,2,3,null,4,5,null]

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

Constraints:

  • 0 <= number of nodes in the tree <= 100
  • -100 <= Node.val <= 100


Company Tags

Please upgrade to NeetCode Pro to view company tags.

root =