ByteByteGo logo
menuProblems List

Lowest Common Ancestor

Medium

Return the lowest common ancestor (LCA) of two nodes, p and q, in a binary tree. The LCA is defined as the lowest node that has both p and q as descendants. A node can be considered an ancestor of itself.

Example:

Constraints:

  • The tree contains at least two nodes.

  • All node values are unique.

  • p and q represent different nodes in the tree.

You can practice coding exercises online by logging into bytebytego.com on your laptop.