In-browser debugger that draws data structures logo

In-browser debugger that draws data structures

Given two nodes p and q from a tree, return their lowest common ancestor.

Share on:

Given two nodes p and q from a tree, return their lowest common ancestor.

Lowest Common Ancestor | ntree.ai ntree.ai ntree.ai Lowest Common Ancestor Visualise Run Submit Description Solutions Submissions Lowest Common Ancestor medium solved attempted Topics Given two nodes p and q from a tree, return their lowest common ancestor. Each node has a reference to its parent node. A node counts as a descendant of itself, so if one of p and q is an ancestor of the other, that ancestor is the answer. Example 1: 3 5 6 2 7 4 1 0 8 Input: tree = [3, null, 5, 1, null, 6, 2, null, 0, 8, null, null, 7, 4], p = 4, q = 6 Output: 5 Example 2: 3 5 6 2 7 4 1 0 8 Input: tree = [3, null

Related listings

Pay-as-you-go Amazon affiliate links that route by country

UK company checks for AI agents, no API key to try

Free PDF road maps of all of the US, Canada, and Mexico in 3.6 GB

make web maps without code and publish them instantly

Hijack an AI agent and try to make it overspend

a Mac photo editor that knows what you clicked