Vertical Order Traversal Problem
Vertical Order Traversal Problem — ExecCode Hard DSA Practice
Solve the Vertical Order Traversal problem on ExecCode. Free online hard DSA practice in Tree. Write and run code in Java, C++, Python — no signup required to run.
Problem description
Given a binary tree in level-order array form, return its vertical order traversal. Treat the root as row 0, column 0. The left child moves to column -1, and the right child moves to column +1. Return columns from left to right. Inside the same column, nodes with smaller row come first; if row and column are both the same, smaller node value comes first.
Examples
Input raw = "[3,9,20,null,null,15,7]"; Output [[9], [3, 15], [20], [7]]. Input raw = "[1,2,3,4,5,6,7]"; Output [[4], [2], [1, 5, 6], [3], [7]]. Input raw = "[1,2,3,4,6,5,7]"; Output [[4], [2], [1, 5, 6], [3], [7]]
Constraints
1 <= number of nodes <= 1000 0 <= node value <= 1000
Practice Vertical Order Traversal free on ExecCode. Browse DSA problems, topic map, and placement guides.