Vertical Order Traversal

Medium Problems DSA practice problem on Onlearn.

Difficulty: easy.

Topics: Vertical Order Traversal of a Binary Tree, Binary Tree, Tree Traversal, Breadth-First Search, Queue, Map, Set, Time Complexity, Space Complexity, level order traversal, map, time complexity analysis, binary tree, bfs, tree traversal, Vertical Order Traversal.

Vertical Order Traversal of a Binary Tree Problem Statement Given the root of a Binary Tree, return its vertical order traversal. This traversal should proceed from the leftmost vertical line to the rightmost vertical line. If multiple nodes share the same vertical line and level, they should be ordered as they appear in a level order traversal (from left to right). Input Format The input will describe the binary tree in a level order traversal, where 1 indicates a null node. Output Format Return a 2D list of integers, where each inner list represents the nodes in a specific vertical column, ordered according to the rules described. Examples Example 1: Explanation: Vertical Levels from left to right: Level 2: [4] Level 1: [2, 5] Level 0: [1, 10, 9, 6] (Overlapping nodes are added in their level order sequence) Level 1: [3] Level 2: [11] Example 2: Explanation: Vertical Levels from left to right: Level 2: [2] Level 1: [7, 5] Level 0: [2, 6] Level 1: [5, 11, 4] (Overlapping nodes are added in their level order sequence) Level 2: [9]