Back to problems

Lowest Common Ancestor (LC 235) with a Follow-Up Variant

Algorithm · Microsoft · Medium

Lowest Common Ancestor in a BST and a Binary Tree Medium · Topics · Company Tags · Hints You need to find the lowest common ancestor (LCA) of two distinct nodes in a binary tree. The LCA is defined as the deepest node that has both target nodes as descendants (a node is allowed to be its own descendant). The problem has two parts. First, you will be given the root of a binary search tree (BST) together with two nodes p and q, and you must compute their LCA using the BST…

Checking your access…