Lowest common ancestor of two nodes
In a binary tree, the lowest common ancestor (LCA) of two nodes p and q is the deepest node that has both p and q in its subtree (a node can be its own ancestor). Return that node.
3
/ \
5 1
/ \
6 2
LCA(6, 2) -> 5
LCA(6, 1) -> 3
Return the LCA node of p and q. Assume both nodes exist in the tree.
Your answer
This one is open-ended. Work it through, then check your reasoning against the full solution.