Problem Name: Vertical Order Traversal
Problem Description:
Vertical Order Traversal
Problem Statement
Given the root of a binary tree, calculate the vertical order traversal of the binary tree.
For each node at position (row, col), its left and right children will be at positions (row + 1, col – 1) and (row + 1, col + 1) respectively. The root of the tree is at (0, 0).
The vertical order traversal of a binary tree is a list of top-to-bottom orderings for each column index starting from the leftmost column and ending on the rightmost column. There may be multiple nodes in the same row and same column. In such a case, sort these nodes by their values.
Return the vertical order traversal of the binary tree.
Note: The merging process must start from the root nodes of both trees. -1 represents a null value here.
I tried :
(https://www.programiz.com/java-programming/online-compiler/)
I was expecting:
Input-> enter image description here
Output-> [[4], [2], [1, 5], [3]]
PRATHAM RAUT is a new contributor to this site. Take care in asking for clarification, commenting, and answering.
Check out our Code of Conduct.