Loading...
Loading...
Loading...
Two people stand in the chart. Their lowest common manager is the deepest node that has both of them in its subtree. A person counts as being in their own subtree. Print the value of that node. All values are different and both people are in the tree.
Example 1
Input
3 5 1 6 2 0 8 null null 7 4 5 1
Output
3
Both lines meet at the root 3.
Example 2
Input
3 5 1 6 2 0 8 null null 7 4 5 4
Output
5
4 is below 5, so 5 is the answer.
Try the problem first. Open one hint at a time.
If the current node is p or q, return it.
If both sides return a node, the current node is the answer.
Write your Python code, run it on the examples and submit it to hidden tests.
Solve in the editor