Problem
Ask
Submissions
Solution

Solution: Vertical Order Traversal of a Binary Tree

Statement

Naive approach

The naive approach would be traversing the tree to get the maximum and minimum horizontal distance of the nodes from the root. Once we have these numbers, we can traverse over the tree again for each distance in the range [maximum, minimum] and return the nodes respectively.

The time complexity of the above algorithm is O(n2)O(n^2), where ...

Problem
Ask
Submissions
Solution

Solution: Vertical Order Traversal of a Binary Tree

Statement

Naive approach

The naive approach would be traversing the tree to get the maximum and minimum horizontal distance of the nodes from the root. Once we have these numbers, we can traverse over the tree again for each distance in the range [maximum, minimum] and return the nodes respectively.

The time complexity of the above algorithm is O(n2)O(n^2), where ...