Problem 1740 · Medium

Find Distance in a Binary Tree

Record depths, mark the path from p to the root, then climb from q; the distance is depth(p) + depth(q) - 2 depth(LCA).

Open the interactive visualisation