Lowest Common Ancestor Of A Binary Tree
1. Given a binary tree, find the lowest common ancestor (LCA) of two given nodes in the tree.Input Format
2. According to the definition of LCA on Wikipedia:
The lowest common ancestor is defined between two nodes p and q as the lowest node in T that has
both p and q as descendants (where we allow a node to be a descendant of itself).
3. If LCA does not exist in the tree print null.
Input is managed for you.Output Format
Output is managed for you.Question Video
1. The number of nodes in the tree is in the range [-1000, 1000].Sample Input
2. -109 <= Node.val <= 109
All Node.val are unique.
p != q
p and q may or may not exist in the tree.
10 5 3 13 null null -2 null null 2 null 1 null null -3 null 11 null nullSample Output
13 3
3
-
Asked in Companies
-
Related Topics
Video Solution
Code Solution
{ }
{ }
Run