SnowScriptWinterOfCode / LeetCode_Q

Solve with us the most mind boggling DSA questions to ace your skills
2 stars 49 forks source link

Day-15 q1: Lowest Common Ancestor of a Binary Tree #364

Closed SonaVarshney closed 7 months ago

SonaVarshney commented 7 months ago

Lowest Common Ancestor of a Binary Tree

Problem Description

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

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).”

Example 1:

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

Example 2:

Input: root = [3,5,1,6,2,0,8,null,null,7,4], p = 5, q = 4
image
Output: 5
Explanation: The LCA of nodes 5 and 4 is 5, since a node can be a descendant of itself according to the LCA definition.

Example 3:

Input: root = [1,2], p = 1, q = 2
Output: 1

Constraints:

SonaVarshney commented 7 months ago

@karishma-2020 @kratika-Jangid @bh-g pls merge the day-15: q1 to the repo. Thanks :) #363

Shubh-Krishna commented 7 months ago

please assign this question to me :) @bh-g @karishma-2020

Akansha77 commented 7 months ago

Please assign this issue to me .

Shubhra-Narang commented 7 months ago

Please assign this issue to me

priyagupta20044 commented 7 months ago

please assign this question to me @bh-g @karishma-2020

i-am-SnehaChauhan commented 7 months ago

@bh-g Please assign it to me

namita0210 commented 7 months ago

Pls assign this issue @bh-g

SonaVarshney commented 7 months ago

@kratika-Jangid @karishma-2020 @bh-g please merge the solution ,thanks :) #380