Lowest Common Ancestor of a Binary Tree
Updated
Problem statement
All node values are unique, and both target values occur in the tree. Return the value of the lowest node whose subtree contains both p and q. A node may be an ancestor of itself.
Function
lowestCommonAncestorValue(root: TreeNode, p: int, q: int) → intExamples
Example 1
root = [3,5,1,6,2,0,8,null,null,7,4]p = 5q = 1return = 3The targets lie in different subtrees of node 3.
Constraints
- The tree contains between
2and10000nodes. - All node values are unique signed 32-bit integers.
Source note: Author-written prompt excerpt retained for source fidelity.
More AMD interview questions
- First-Fit Arena AllocatorPHONE SCREEN · ONSITE INTERVIEW · Seen Sep 2026
- Matrix Multiplication and Parallel PartitionsPHONE SCREEN · ONSITE INTERVIEW · Seen Oct 2025
- Copy Non-overlapping Byte BuffersPHONE SCREEN · ONSITE INTERVIEW · Seen Jan 2025
- Set and Clear BitsPHONE SCREEN · Seen Feb 2020
- AND Gate with MultiplexersPHONE SCREEN · Seen Jul 2018
- XOR Gate with MultiplexersPHONE SCREEN · Seen Jul 2018
- Insert After a Linked-List NodeONSITE INTERVIEW · Seen Oct 2026
- LRU CacheONSITE INTERVIEW · Seen Oct 2026
- Sort a Binary ArrayONSITE INTERVIEW · Seen Oct 2026
- Predict Runtime Method DispatchONSITE INTERVIEW · Seen Oct 2026
Similar questions at other companies
- N-ary Index-Path Encoder and DecoderBloomberg LP · PHONE SCREEN · ONSITE INTERVIEWBloomberg LP interview questions
- House Robber IIIOkta · PHONE SCREENOkta interview questions
- Render a Task Tree from CSV RowsStripe · PHONE SCREEN · ONSITE INTERVIEWStripe interview questions
- Validate Binary Search TreeKotak Mahindra Bank · PHONE SCREENKotak Mahindra Bank interview questions
- House Robber IIIGoldman Sachs · PHONE SCREENGoldman Sachs interview questions
- Binary Tree Target-Sum PathsByteDance · PHONE SCREENByteDance interview questions
- House Robber IIIVisa · PHONE SCREENVisa interview questions
- Find All Paths for a Name in a File SystemThe Walt Disney Company · PHONE SCREENThe Walt Disney Company interview questions
- Validate a BST with a Custom ComparisonApple · PHONE SCREENApple interview questions
- Filter Undesired Comments and Their DescendantsReddit · PHONE SCREEN · ONSITE INTERVIEWReddit interview questions
Interview reports that mention this question
AMD interview experiences
- AMD GPU and Verification Interviews: 3 Experiences (Part 3 of 3)
- AMD SDE2 and AI Engineer Interviews: 7 Experiences (Part 2 of 3)
- AMD New Grad Role Interviews: 3 Experiences (Part 2 of 2)
- AMD ML and GPU Intern Interviews: 7 Experiences (Part 2 of 2)
- AMD Interviews by Role, Level Not Reported: 9 Experiences