
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^4root = [1,2,3,4,5,6,7]Output[4, 2, 12, 3, 7]WhyColumn `-2` has `4`, column `-1` has `2`, column `0` has `1 + 5 + 6 = 12`, column `1` has `3`, and column `2` has `7`.root = [3,9,20,null,null,15,7]Output[9, 18, 20, 7]WhyNode `9` is in column `-1`, nodes `3` and `15` are in column `0`, node `20` is in column `1`, and node `7` is in column `2`.root = []Output[]WhyAn empty tree has no vertical columns, so the result is an empty list.`0 <= number of nodes <= 10^5``-10^4 <= node.val <= 10^4`Each node has fields `val`, `left`, and `right`The tree may be skewed or balancedReturn sums ordered from leftmost column to rightmost columndef vertical_column_sums(root):