Deepest Shared Ancestor of Two Nodes in a Binary Tree
Asked at Uber · Coding Questions · Difficulty: Medium · Last asked Feb 26, 2026
An organisation chart, a file-system tree or a phylogenetic tree often needs one query: given two members, which is the most specific group that contains both? In a binary tree this is the deepest node that has both target nodes in its subtree. Given a binary tree with unique values and two values that occur in it, return the value of that node.
Loading the problem…