At Meta, you may need to aggregate tree-structured data by vertical alignment. Given the root of a binary tree, return the sum of node values in each vertical column from leftmost column to rightmost column.
A node's column index is defined relative to the root:
0c is in column c - 1c is in column c + 1Implement a function:
root, the root node of a binary tree, or null for an empty treeExample 1
Input: root = [1,2,3,4,5,6,7]
Output: [4,2,12,3,7]
Explanation: Columns are -2:[4], -1:[2], 0:[1,5,6], 1:[3], 2:[7].
Example 2
Input: root = [3,9,20,null,null,15,7]
Output: [9,18,20,7]
Explanation: Columns are -1:[9], 0:[3,15], 1:[20], 2:[7].
[0, 10^5]-10^4 <= node.val <= 10^4