FastPrepLowest Common Ancestor of a Binary Tree
Problems/Lowest Common Ancestor of a Binary Tree

Lowest Common Ancestor of a Binary Tree

AMD logoAMD● MediumFULLTIMEPHONE SCREEN

Updated Nov 2026

QuestionFunctionExamplesConstraints

Problem statement

Source note: Reported in an AMD full-time phone screen. The report names a well-known problem. We chose the function signature, a fixed order for the output, and the input limits. Our version is about 98% the same as the reported question.

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) → int

Examples

Example 1

root = [3,5,1,6,2,0,8,null,null,7,4]p = 5q = 1return = 3
root
356274108

The targets lie in different subtrees of node 3.

Constraints

  • The tree contains between 2 and 10000 nodes.
  • 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 Experienced SWE Interviews: 6 Experiences (Part 1 of 3)

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
All AMD interview questionsSee AMD hiring insights
Saved
/**
 * Definition for a binary tree node.
 * public class TreeNode {
 *     int val;
 *     TreeNode left;
 *     TreeNode right;
 *     TreeNode() {}
 *     TreeNode(int val) { this.val = val; }
 *     TreeNode(int val, TreeNode left, TreeNode right) {
 *         this.val = val;
 *         this.left = left;
 *         this.right = right;
 *     }
 * }
 */
class Solution {
    public int lowestCommonAncestorValue(TreeNode root, int p, int q) {
      // Write your code here.
    }

}
Checking account…