Python data engineering interview problem. Difficulty: advanced. Pattern: Trees. About 18 minutes. Part of the Pro drill bank.
Lowest common ancestor in a BST given as level-order. Treat this as a production helper: match the contracted return shape, including empty and duplicate inputs.
Implement lowest_common_ancestor(level_order: list, p: int, q: int) -> int.
Input: lowest_common_ancestor([6, 2, 8, 0, 4, 7, 9, None, None, 3, 5], 2, 8) Output: 6 2 and 8 split at root.
Topics: lakebench, python, bst, lca.
More Python interview questions · All interview problems · Learn data engineering
Interview-style drill: Lowest common ancestor in a BST given as level-order.
Implement `lowest_common_ancestor(level_order: list, p: int, q: int) -> int`. Example: tree `[6, 2, 8, 0, 4, 7, 9, None, None, 3, 5]`, p=2, q=8 → `6`. Keep the harness.