236. Lowest Common Ancestor of a Binary Tree | [Super Important] | LCA of Binary Tree

preview_player
Показать описание
In this video, I'll talk about how to solve Leetcode 236. Lowest Common Ancestor of a Binary Tree | [Super Important] | LCA of Binary Tree

Let's Connect:

About Me:
I am Aryan Mittal - A Software Engineer in Goldman Sachs, Speaker, Creator & Educator. During my free time, I create programming education content on this channel & also how to use that to grow :)

✨ Timelines✨
0:00 - Problem Explanation
2:42 - Brute Force
3:30 - Intuition & Explanation
7:56 - Understanding Core LCA logic & Dry Run
14:24 - More Dry Run

✨ Hashtags ✨
#programming #Interviews #leetcode #faang #maang #datastructures #algorithms
Рекомендации по теме
Комментарии
Автор

please solve this one: Selling Pieces of Wood

floatingpoint
Автор

public TreeNode lowestCommonAncestor(TreeNode root, TreeNode p, TreeNode q) {
if(root == null || root == p || root == q) return root;

TreeNode leftLca = lowestCommonAncestor(root.left, p, q);
TreeNode rightLca = lowestCommonAncestor(root.right, p, q);

if(leftLca == null) return rightLca;

if(rightLca == null) return leftLca;

return root;
}

mystatuses