First Common Ancestor
Design an algorithm to find the first common ancestor of two nodes in a binary tree.
Avoid storing additional nodes in a data structure.
Note: This is not necessarily a binary search tree.
Example:
8
/ \
3 1
/ \
2 4
FCA(2, 4) = 3
FCA(2, 3) = 3
FCA(2, 1) = 8
Hints
solution.py
Python ready
Test Output
▶
Click "Run Tests" to execute your code