How can you find the lowest common ancestor of 2 given nodes in a binary tree data structure.
Node:
- val: int
- right: Node
- left: Node
Write a function findLCA(Node node1, Node node2) -> Node
findLCA(Node(7), Node(4)) -> Node(2) findLCA(Node(7), Node(6)) -> Node(5)
How can this be improved if tree is a Binary Search Tree?