Lowest common ancestor BST

Write codeEasy20 minAmazon and Meta style

Your task

Given a binary search tree as a level-order array (None marks a missing child) and two values p and q that are both present, return the value of their lowest common ancestor. Exploit the BST ordering instead of a general-tree LCA: starting at the root, go left when both p and q are smaller than the current node, go right when both are larger, and otherwise the current node is the split point and therefore the LCA. Return the LCA value.

Examples

lca_bst(level: list, p: int, q: int) -> int
Example 1
Inputlca_bst([6, 2, 8, 0, 4, 7, 9, None, None, 3, 5], 2, 8)
Output6