Skip to content
CampusEduX

Vertical Order Traversal

Hardjavapythonccppjavascript

Group the nodes of a binary tree by their horizontal distance from the root (root at distance 0, each left step -1, each right step +1). Within a column, list nodes in breadth-first order.

Input Format

The first line contains an integer M, the number of level-order tokens. The second line contains M space-separated tokens (integers or null).

Output Format

Print one line per column, from leftmost to rightmost, values separated by single spaces.

Related Problems

  • Serialize and Deserialize Binary Tree
    Hard · java, python, c, cpp, javascript
    Solve Problem
  • Maximum Path Sum in Binary Tree
    Hard · java, python, c, cpp, javascript
    Solve Problem
  • Boundary Traversal
    Hard · java, python, c, cpp, javascript
    Solve Problem

Input (stdin)

Output

Run your code to see output here...