Exercises/#35 Lowest Common Ancestor
#35

Lowest Common Ancestor

Medium🌳 Trees
90 XP

Problem

Given a binary search tree and two nodes p and q, find their lowest common ancestor (LCA).

Examples

Input: root=[6,2,8,0,4,7,9], p=2, q=8
Output: 6

Input: root=[6,2,8,0,4,7,9], p=2, q=4
Output: 2
treebstrecursion
AI Assistantβ€” powered by AI

Unlock hints progressively β€” start gentle, go deeper only if needed.

πŸ’‘

Level 1: Gentle Nudge

A subtle direction

πŸ—ΊοΈ

Level 2: Approach

The algorithm to use

πŸ”

Level 3: Detailed

Step-by-step guidance

35 / 150

Your Solution

⚑ JavaScript

to save progress and use AI features