Lowest Common Ancestor
Asked in the Coding Round stage. Given a binary tree with unique integer values and two existing target values, return the value of their lowest common ancestor.
The tree is represented recursively as [value, left, right], where an empty child is null. Implement lowest_common_ancestor(root, p, q).
Examples
[3,[5,[6,null,null],[2,[7,null,null],[4,null,null]]],[1,[0,null,null],[8,null,null]]], p=5, q=1 returns 3.p=5, q=4 returns 5.Constraints
1 <= nodes <= 10^5p != q.def lowest_common_ancestor(root, p, q):