Community

Start a Thread


Notifications
Subscribe You’re not receiving notifications from this thread.

Nodes in Binary Tree Columns (Main Thread)

Here is the interview question prompt, presented for reference.

The columns of a binary tree are traversed in a top-to-bottom order, starting from the leftmost nodes to the rightmost nodes of the tree. This traversal of columns of a binary tree is called vertical order traversal.

Given the root of a binary tree, find the vertical order traversal of the binary tree. You are required to specify all the nodes that are visited during the traversal of each column. There may be multiple nodes in the same row and same column. In such a case, sort these nodes by their values.

For each node at position (row, col), its left and right children will be at positions (row + 1, col - 1) and (row + 1, col + 1) respectively. The root of the tree is at (0, 0).

![image](https://storage.googleapis.com/algodailyrandomassets/curriculum/binary-search-trees/nodes-binary-tree-columns/problem.png)

Constraints

  • The number of nodes in the tree is in the range [1, 1000]
  • 0 <= Node.val <= 1000

You can see the full challenge with visuals at this link.

Challenges • Asked 6 months ago by Jake from AlgoDaily

Jake from AlgoDaily Commented on Dec 16, 2022:

This is the main discussion thread generated for Nodes in Binary Tree Columns (Main Thread).