Tap here to switch tabs
Problem
Submissions

Problem: Vertical Order Traversal of a Binary Tree

Vertical Order Traversal of a Binary Tree returns node values grouped by column, from leftmost to rightmost, with each column ordered top to bottom and left to right for ties.

Statement

Given the root of a binary tree, return the vertical order traversal of its nodes' values.

The nodes should be grouped into columns based on their horizontal position in the tree:

  • The root is at column 0.

  • The left child of a node is one column to the left of its parent.

  • The right child of a node is one column to the right of its parent.

  • Return the columns from the leftmost column to the rightmost column.

  • Within each column, return nodes from top to bottom.

  • If two nodes have the same row and column, they should appear from left to right.

Constraints:

  • The number of nodes in the tree is in the range [0, 100].

  • −100≤-100 ≤ Node.val ≤100≤ 100

⋮
Tap here to switch tabs
Problem
Submissions

Problem: Vertical Order Traversal of a Binary Tree

Vertical Order Traversal of a Binary Tree returns node values grouped by column, from leftmost to rightmost, with each column ordered top to bottom and left to right for ties.

Statement

Given the root of a binary tree, return the vertical order traversal of its nodes' values.

The nodes should be grouped into columns based on their horizontal position in the tree:

  • The root is at column 0.

  • The left child of a node is one column to the left of its parent.

  • The right child of a node is one column to the right of its parent.

  • Return the columns from the leftmost column to the rightmost column.

  • Within each column, return nodes from top to bottom.

  • If two nodes have the same row and column, they should appear from left to right.

Constraints:

  • The number of nodes in the tree is in the range [0, 100].

  • −100≤-100 ≤ Node.val ≤100≤ 100