How to find the lowest common ancestor of two nodes in any binary tree?
Starting from root node and moving downwards if you find any node that has either p or q as its direct child then it is the LCA. (edit – this should be if p or q is the node’s value, return it. Otherwise it will fail when one of p or q is a direct … Read more