codementor on Nostr: Question: In a binary tree (not a search tree), find the first common ancestor of two ...
Question: In a binary tree (not a search tree), find the first common ancestor of two nodes: the lowest node that has both of them below it (a node counts as below itself).
There are no parent links, and you may not store nodes in an extra data structure.
(CtCI 4.8)
Try to answer before you open the reply.
#tg008 · TG-008-Q1
Published at
2026-10-27 15:07:54 UTCEvent JSON
{
"id": "bee5691549f89c0ca8d109b18b9261188c931a13c0bcfa986c0eeda6ee35dd01",
"pubkey": "e68a0856e90d9997b1f721e905249896412dd570399a987b2e8fd5e7fcfe2279",
"created_at": 1793113674,
"kind": 1,
"tags": [
[
"t",
"tg008"
]
],
"content": "Question: In a binary tree (not a search tree), find the first common ancestor of two nodes: the lowest node that has both of them below it (a node counts as below itself).\n\nThere are no parent links, and you may not store nodes in an extra data structure.\n\n(CtCI 4.8)\n\nTry to answer before you open the reply.\n\n#tg008 · TG-008-Q1",
"sig": "855d794f71875ee0f492ba552c9af4aaab9b7b62b485e677067d8822ec481d460b0980ee1f1488a15ac30302234ad0b9b23fd228006dfdeb2e3afbf778afd595"
}