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

Lowest Common Ancestor of a Binary Tree

Atlassian logoAtlassian● MediumFULLTIMEOA

Updated Nov 2026

QuestionFunctionExamplesConstraints

Problem statement

Source note: Reported in an Atlassian full-time online assessment. The report links to the exact Lowest Common Ancestor of a Binary Tree exercise but does not copy its full statement. Our version follows that linked exercise and uses a fixed function interface.

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.

More Atlassian Online Assessment questions

  • Planning ProductionOA · Seen Feb 2025
  • K-Means ClusteringOA · Seen Feb 2025
  • Minimum Sorted Erasure OperationsOA · Seen Jun 2024
  • Count Analogous ArraysOA · Seen Mar 2024
  • Get Maximum ScoreOA · Seen Mar 2024
  • Better Compression 🦀OA · Seen Mar 2024
  • Romanizer 🐡OA · Seen Mar 2024
  • Flower Bouquets 💐OA · Seen Mar 2024
  • Binary Search Tree IteratorOA · Seen Nov 2023
  • Binary Tree Level Order TraversalOA · Seen Nov 2023

Similar questions at other companies

  • Base Unit ConversionsAdobe · OAAdobe interview questions
  • Count Prime Values in SubtreesVisa · OAVisa interview questions
  • Part 1: The Narrowest KeyScale AI · OAScale AI interview questions
  • Sewer Drainage PartitionTwo Sigma · OATwo Sigma interview questions
  • Merge Row Trees by Key PathHudson River Trading · OAHudson River Trading interview questions
  • Count Balanced Nodes in a Rooted TreeDRW · OADRW interview questions
  • Chain of CommandIMC Trading · OAIMC Trading interview questions
  • Construct Binary Tree S-ExpressionOptiver · OAOptiver interview questions
  • Chain of CommandUber · OAUber interview questions
  • Maximum Data Transfer TimeMicrosoft · OAMicrosoft interview questions

Atlassian interview experiences

  • Atlassian MLE Phone Screen: Model Deployment Design: 1 Experience
  • Atlassian Coding Screens and Karat: 3 Experiences (Part 2 of 2)
  • Atlassian Full Stack Interviews: 11 Experiences (Part 1 of 2)
All Atlassian interview questionsSee Atlassian 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…