Sponsored
Sponsored
Use these hints if you're stuck. Try solving on your own first.
Starting from the root, traverse the left and the right subtrees, checking if one of the nodes exist there.
If one of the subtrees doesn't contain any given node, the LCA can be the node returned from the other subtree
If both subtrees contain nodes, the LCA node is the current node.