Find lowest common ancestor in tree
Company: Microsoft
Role: Software Engineer
Category: Coding & Algorithms
Difficulty: medium
Interview Round: Technical Screen
Quick Answer: This question evaluates understanding of tree data structures and the lowest common ancestor concept, contrasting use of binary search tree ordering with the general binary tree case while requiring algorithmic time and space complexity reasoning in the Coding & Algorithms domain.
Lowest Common Ancestor in a BST
Constraints
- Inputs are Python literals matching the function signature.
- Return a deterministic exact-match value.
Examples
Input: ([6,2,8,0,4,7,9,None,None,3,5], 2, 8)
Expected Output: 6
Explanation: Root split.
Input: ([6,2,8,0,4,7,9,None,None,3,5], 3, 5)
Expected Output: 4
Explanation: LCA in left subtree.
Hints
- Use deterministic tie-breaking for prompts with multiple valid outputs.
- For design-style APIs, simulate operations with explicit inputs.
Lowest Common Ancestor in a General Binary Tree
Constraints
- Inputs are Python literals matching the function signature.
- Return a deterministic exact-match value.
Examples
Input: ([3,5,1,6,2,0,8,None,None,7,4], 5, 1)
Expected Output: 3
Explanation: Root LCA.
Input: ([3,5,1,6,2,0,8,None,None,7,4], 7, 4)
Expected Output: 2
Explanation: Nested LCA.
Hints
- Use deterministic tie-breaking for prompts with multiple valid outputs.
- For design-style APIs, simulate operations with explicit inputs.