Back to problems

Lowest Common Ancestor of a Binary Search Tree (LC 235)

Algorithm · Amazon · Easy

You are given a binary search tree in which every node holds a distinct value, along with two different nodes that are both guaranteed to be present in the tree. Find the lowest node that has both of those nodes among its descendants. A node is allowed to count as a descendant of itself, so if one of the two given nodes sits above the other, that node is the answer. This is the standard formulation used for practice. The exact function signature and any follow-up questions…

Loading the rest of the question…