← All problems

Lowest Common Ancestor (Binary Tree)

Medium treesrecursion LeetCode ↗
Find the lowest common ancestor of two nodes in a binary tree.

Hints (0/3 revealed)

Log in to reveal hints progressively.

Complexity

Time O(n), Space O(h)

Common pitfalls

  • Assuming BST properties in a general tree
  • Not handling p == q

Your solution

Log in to save your code and track progress.