Dsa
Trees
Easy
Vertical Order Traversal
Write a program to perform a vertical order traversal of a binary tree. Nodes that are in the same vertical level should be grouped together. The leftmost nodes have the smallest index and the rightmost nodes have the largest index. The output should contain lists of nodes in vertical order, starting from the leftmost.
Input format:
A series of integers in level order, where 'N' represents a null node.
Example Input:
1 2 3 4 5 6 7
Output format:
A list of lists representing the vertical order traversal of the tree.
Example:
Input:
1 2 3 4 5 6 7
Output:
[[4],[2],[1],[3],[5],[6],[7]]
Key concepts
treestraversalvertical
Practise this out loud — free
Start a mock interview on THIS exact question — a voice AI interviewer opens with it, pushes back like a real onsite, then hands you an instant scorecard.
🎙 Practise this question now