Problem · Tree
Lowest Common Ancestor of a Binary Tree
Learn this problemProblem 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.
More Atlassian problems
- 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