20. Lowest Common Ancestor of a Binary Tree (LeetCode) | DFS Pattern | Binary Tree Tutorials | Code

preview_player
Показать описание
#tree #datastructures #interview

Hello viewers!

In this video, we have discussed the 6th problem on DFS i.e Lowest Common Ancestor of a Binary Tree LeetCode.
----------------------------------------------------
----------------------------------------------------
----------------------------------------------------
----------------------------------------------------
----------------------------------------------------

Please consider subscribing to the channel.

Extra video covers:

Tree Data Structures
Binary Tree Data Structures
Video Series on Tree
Best Tree Videos
Beginner to Advanced
Binary Tree Tutorials
Tree Tutorials
Рекомендации по теме
Комментарии
Автор

At 7:50 (mm:ss) -
For storing paths, assuming that the binary tree is not skewed, the space required is O(log N). Otherwise, O(N) space is required in the case of the Skew Tree.

aakashverma
Автор

The way you are explaining the problem theory and it's solution is so cool . So please continue this process.

Entertainment-lzei
Автор

To be honest, sir you have made DFS look so easy.👏👏
Simply a masterpiece🔥🔥👌👌

surabhsaxena
Автор

# Definition for a binary tree node.
# class TreeNode:
# def __init__(self, x):
# self.val = x
# self.left = None
# self.right = None

class Solution:
def lowestCommonAncestor(self, root: 'TreeNode', p: 'TreeNode', q: 'TreeNode') -> 'TreeNode':
return self.lca(root, p, q)

def lca(self, root, p, q):
if root ==None:
return None
elif root == p or root==q:
return root
else:
left = self.lca(root.left, p, q)
right = self.lca(root.right, p, q)

if left==None and right==None:
return None
elif left!=None and right!=None:
return root
elif left==None:
return right
elif right==None:
return left

dsaaz
Автор

Is this playlist covers all topic asked from trees in interview??

amansrivastava
Автор

Best explanation lekin kaashi itna deemag coding round mein chalta

RishabhMishra-uwyb