Lowest Common Ancestor of Deepest Leaves
Solve this the way you would in the interview: out loud, on a timer, with an AI interviewer asking follow-ups while you code. You get a scored report at the end.
Practice this as a mock interviewFree to start, no account neededProblem
Given the root of a non-empty binary tree with distinct values, consider the nodes at the **maximum depth** (the deepest leaves). Find their lowest common ancestor: the deepest node whose subtree contains every one of them. If there is only one deepest node, it is its own ancestor.
Return that node; the grader serializes the **subtree rooted at it** in level order.
A single post-order pass that returns (depth, candidate) pairs runs in O(n).
Examples
Constraints
- 1 <= number of nodes <= 1000
- 0 <= Node.val <= 1000
- All values are distinct
What the interviewer grades
A correct solution is one of five scores. The report also grades problem understanding (did you clarify inputs and edge cases before coding), problem solving, communication while you work, code quality, and testing. See a sample report, or read up on the pattern in the lessons.