Leetcode 1257. Smallest Common Region

Posted on Fri 22 November 2024 in Leetcode Premium • Tagged with least-common-ancestor

Question Link : https://leetcode.com/problems/smallest-common-region/

Difficulty: Medium

Premium: True

Question

You are given some lists of regions where the first region of each list includes all other regions in that list. Naturally, if a region x contains another region y then x is bigger than y. Also, by …


Continue reading

Leetcode 1644. Lowest Common Ancestor of a Binary Tree II

Posted on Fri 22 November 2024 in Leetcode Premium • Tagged with least-common-ancestor

Question Link : https://leetcode.com/problems/lowest-common-ancestor-of-a-binary-tree-ii/

Difficulty: Medium

Premium: True

Question

Given the root of a binary tree, return the lowest common ancestor (LCA) of two given nodes, p and q. If either node p or q does not exist in the tree, return null. All values of the …


Continue reading

Leetcode 1650. Lowest Common Ancestor of a Binary Tree III

Posted on Fri 22 November 2024 in Leetcode Premium • Tagged with least-common-ancestor

Question Link : https://leetcode.com/problems/lowest-common-ancestor-of-a-binary-tree-iii/

Difficulty: Medium

Premium: True

Question

Given two nodes of a binary tree p and q, return their lowest common ancestor (LCA). Each node will have a reference to its parent node. The definition for Node is below:

class Node { public int val; public …


Continue reading

Leetcode 0236. Lowest Common Ancestor of a Binary Tree

Posted on Wed 20 November 2024 in Leetcode • Tagged with least-common-ancestor

Question Link : https://leetcode.com/problems/lowest-common-ancestor-of-a-binary-tree/

Difficulty: Medium

Premium: False

Question

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 …


Continue reading