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

LeetCode-style React challenges with in-browser tests

a 2D web renderer, 2–4× faster than the most popular one

See which countries your money ends up in

Hosted cron for HTTP jobs and commands behind a firewall

Convert documents to Markdown locally in the browser

Drop prompt injections at Token 0 before LLM inference