Coding Challenge

Lowest Common Ancestor of a Binary Search Tree

Easy
treebst

Find the lowest common ancestor of two nodes in a BST.

Given a BST and two nodes p and q, return their lowest common ancestor.

Examples

Input: root = [6,2,8,0,4,7,9,null,null,3,5], p = 2, q = 8

Output: 6

Constraints

  • Both nodes exist in the BST

Preparing your coding workspace...