FrontendChallenges is a collection of frontend interview questions and answers. It is designed to help you prepare for frontend interviews. It's free and open source.
difficulty: medium
title: Lowest Common Ancestor in Binary Search Tree
type: question
template: typescript
tags: javascript, blind75, binary-search-tree, recursion
Question
Given a binary search tree (BST) where all node values are unique, and two nodes p and q, find their lowest common ancestor (LCA).
The lowest common ancestor of two nodes is defined as the deepest node in the tree that has both nodes as descendants. A node can be considered a descendant of itself.
Info
Question
Given a binary search tree (BST) where all node values are unique, and two nodes
p
andq
, find their lowest common ancestor (LCA).The lowest common ancestor of two nodes is defined as the deepest node in the tree that has both nodes as descendants. A node can be considered a descendant of itself.
Constraints:
Examples:
Template
index.ts
index.test.ts