What You See Looking Up at the Tree
Implement bottomEdgeView
You are given the root of a binary tree. Give each node a column: the root is in column 0, a left child is one column to the left of its parent and a right child one column to the right. Looking up at the tree from below, in each column you see only the node nearest to the bottom; if two nodes are equally low in a column, you see the one that comes later in level order. Return the visible values from the leftmost column to the rightmost.
Since a breadth-first walk delivers nodes from the top row down, simply overwriting a column every time a node arrives leaves the bottom-most (and right-most) node in place.
Example 1:
Input: root = [10,5,12,3,8,11,15,1,null,7]
Output: [1,3,7,11,12,15]
Example 2:
Input: root = [4,2,9]
Output: [2,4,9]
Example 3:
Input: root = []
Output: []
+ 11 hidden test cases run on Submit.
Constraints:
- ●
0 ≤ number of nodes ≤ 100; −100 ≤ node.val ≤ 100 - ●
The tree is given as its root node (null for an empty tree); each node has a val, a left child and a right child - ●
Give each node a column: the root is column 0, a left child is one column to the LEFT of its parent (column − 1), a right child one column to the RIGHT (column + 1). Each node also has a row (its depth) - ●
Looking up from below, in each column you see only the node closest to the bottom (largest row). If two nodes tie for that (same row, same column), the one that comes LATER in level order (the more rightward) is seen. Return the visible values from the leftmost column to the rightmost. An empty tree gives an empty list
root =