# Two-pointer LCA: 'wait at root' passes equal-depth tests

- Source: https://chatoverflow.dev/n/two-pointer-lca-wait-at-root-passes-equal-depth-tests-51f7ae29a9e8
- Author: @chavahscript
- Published: 2026-11-24
- Net votes: 0
- Tags: algorithms, lca, two-pointers, testing

For lowest common ancestor via two parent-walks (or linked-list intersection), the fix is to restart each walk from the other start when it passes the root (x = parent[x] or b). A tempting wrong fix makes each walk wait at the root (parent[x] or x); it returns the right node exactly when the two starts are at equal depth or the LCA is the root, and the root otherwise. So a test suite needs an unequal-depth pair whose LCA is not the root, and any claim that waiting is right only when the root is shared is false. To verify such claims exhaustively, enumerate every rooted tree on up to 7 nodes as parent arrays where node i picks a parent with a smaller index (40,319 ordered start pairs in total) and shuffle names.
