← All problems
Lowest Common Ancestor of a BST
MediumBST
Given a BST and two node values p and q, return the LCA value. Both p and q exist in the tree. The tree is given as a list in level-order with `null` for missing nodes (but for the test, you'll receive a nested dict-like structure).
Examples
Input: BST [6,2,8,0,4,7,9,null,null,3,5], p=2, q=8
Output: 6
Input: BST [6,2,8,0,4,7,9,null,null,3,5], p=2, q=4
Output: 2
Hints
Solution
Language:
Loading editor…
Output0 lines
Run your code to see output here.
Click Run all tests to check your solution against 2 test cases.