LeetCode 235 Lowest Common Ancestor of BST - Problem Statement

The problem

Given a Binary Search Tree and two nodes p and q, find their Lowest Common Ancestor (LCA).

The LCA is the deepest node that has both p and q as descendants (a node can be its own descendant).

With this BST and p = 2, q = 8:

        6
       / \
      2   8
     / \ / \
    0  4 7  9

The LCA is 6. Both 2 and 8 are descendants of 6, and no deeper node contains both.

If p = 2 and q = 4, the LCA is 2 (since 2 is an ancestor of 4, and a node can be its own ancestor).

Constraints: All values are unique. p and q exist in the tree.