Back to problems

Lowest Common Ancestor with Parent Pointers (LeetCode 1650)

Algorithm · Salesforce · Medium

Lowest Common Ancestor with Parent Links Medium · Tree, Two Pointers You are given two nodes p and q belonging to a binary tree. Every tree node holds a reference to its parent node; the root’s parent is set to null. The root itself is not directly accessible. Your task is to return the lowest common ancestor (LCA) of p and q. The LCA is the deepest node that is an ancestor of both input nodes. If p and q reside in two disconnected trees (they share no common ancestor),…

Checking your access…