Back to DSA sheet

Lowest Common Ancestor of BST

MediumBST
Open on LeetCodeAmazonGoogleMeta

Given a binary search tree and two nodes, return their lowest common ancestor.

Constraints
  • 2 <= nodes <= 10^5
  • All Node.val are unique
  • p != q
Sheets
Blind 75Grind 75NeetCode 150
lowest-common-ancestor-of-bst.cpp
Loading editor
Custom input (stdin)
Output

Run your code to see its output.