Problem Description
Given a binary tree A consisting of N nodes, return a 2-D array denoting the vertical order traversal of A.
Go through the example and image for more details.
NOTE:
0 <= N <= 104
First and only argument is an pointer to root of the binary tree A.
Return a 2D array denoting the vertical order traversal of A.
Input 1:
6 / \ 3 7 / \ \ 2 5 9
Input 2:
1 / \ 2 3 / \ 4 5
Output 1:
[ [2], [3], [6, 5], [7], [9] ]
Output 2:
[ [4], [2], [1, 5], [3] ]
Explanation 1:
Nodes on Vertical Line 1: 2 Nodes on Vertical Line 2: 3 Nodes on Vertical Line 3: 6, 5 As 6 and 5 are on the same vertical level but as 6 comes first in the level-order traversal of the tree so we will output 6 before 5. Nodes on Vertical Line 4: 7 Nodes on Vertical Line 5: 9
Explanation 2:
Nodes on Vertical Line 1: 4 Nodes on Vertical Line 2: 2 Nodes on Vertical Line 3: 1, 5 Nodes on Vertical Line 4: 3
NOTE: You only need to implement the given function. Do not read input, instead use the arguments to the function. Do not print the output, instead return values as specified. Still have a question? Checkout Sample Codes for more details.