Lowest Common Ancestor of a Binary Search Tree

You are given the root of a binary search tree and two node values p and q. Return the value of their lowest common ancestor (LCA).

The lowest common ancestor is the deepest node that is an ancestor of both nodes. A node counts as an ancestor of itself, so when one target lies on the path to the other, that target is the answer.

Examples
Input: [[6,2,8,0,4,7,9,null,null,3,5],2,8]
Output: 6
Hints

Lowest Common Ancestor of a Binary Search Tree

You are given the root of a binary search tree and two node values `p` and `q`. Return the value of their lowest common ancestor (LCA).