Binary Search Tree : Lowest Common Ancestor HackerRank Solution

You are given pointer to the root of the binary search tree and two values v1and v2. You need to return the lowest common ancestor (LCA) of v1 and v2 in the binary search tree.

In the diagram above, the lowest common ancestor of the nodes 4 and 6 is the node 3. Node 3 is the lowest node which has nodes 4 and 6 as descendants.

Function Description

Complete the function lca in the editor below. It should return a pointer to the lowest common ancestor node of the two values…