Read a binary tree as a family tree with the root as the eldest ancestor. Its deepest leaves, the leaves farthest from the root, are the youngest generation. Return the value of the nearest node that has every one of them below it or is one of them itself (the lowest common ancestor of the deepest leaves). If only one leaf is deepest, it is its own nearest such node, so return that leaf's value.
Examples
1
/ \
2 3
/ \
4 5
/ \
7 8
Input: root = build_tree([1, 2, 3, 4, 5, None, None, 7, 8])
Output: 4
Explanation: the deepest leaves are 7 and 8, and node 4 is the lowest node above both.
Input: root = build_tree([1, 2, 3, 4, 5, None, 6, None, None, 7, 8, 9])
Output: 1
Explanation: the deepest leaves 7, 8 and 9 sit on both sides of the root.
Input: root = build_tree([1, 2, 3, 4])
Output: 4
Explanation: 4 is the only deepest leaf, so the smallest subtree holding it is the leaf itself.
Constraints
1 <= number of nodes <= 1000- All values are distinct
Goals
- Return a pair (height, node) from a single post-order pass
- Decide the answer at the node where two equal heights meet