Skip to content

Latest commit

 

History

History
13 lines (10 loc) · 390 Bytes

File metadata and controls

13 lines (10 loc) · 390 Bytes

Problem 8: Universal Ancestry (Binary Tree)

Problem Statement

Given a binary tree, find the lowest common ancestor (LCA) of two given nodes, p and q.

Input Format

  • The root of a binary tree.
  • Two target nodes p and q.

Example

Input: root = [3, 5, 1, 6, 2, 0, 8, null, null, 7, 4], p = 5, q = 1
Output: 3
Explanation: The LCA of nodes 5 and 1 is 3.