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.
Input: root = [3,9,20,null,null,15,7]
Output: [[9],[3,15],[20],[7]]
Explanation:
Column -1: Only node 9 is in this column.
Column 0: Nodes 3 and 15 are in this column in that order from top to bottom.
Column 1: Only node 20 is in this column.
Column 2: Only node 7 is in this column.
Get notified about all off campus jobs/interviews and the process.
We are building our website and it will be back soon with lots of content till then subscribe us on youTube.
https://t.me/tech_geek1
My LinkedIn page: / techgeek1
Interview Preparation Sheet: • INTERVIEW PREPARATION SHEET - HASHEDIN and...
Link for Leetcode solutions: • Placements 2022
Link for placement series:
Placement 2022: • Placements 2022
Placement 2023: • Placements 2023
#leetcode #leetcodesolution