My first instinct was to just walk both nodes up to the root and collect the paths, then compare.
Since parent pointers are available, treat the problem as finding the intersection of two linked lists: compute the depth of each node by walking up to the root, align the deeper node, then move both pointers up in tandem until they meet. This yields O(h) time and O(1) space, where h is the tree height.
Pro tip: Mention that you can avoid computing depths by using a two-pointer technique where each pointer traverses up to the root and then switches to the other node's path; they will meet at the LCA after at most two passes. This demonstrates deeper insight and often impresses interviewers.
Confirm that parent pointers are valid, nodes are in the same tree, and p and q are distinct. Ask about edge cases like one node being the ancestor of the other.
Write a helper function to find the depth of a node by following parent pointers until null. Compute depths for both p and q.
Move the deeper node up by the difference in depths so that both pointers are at the same level.
Move both pointers up simultaneously until they point to the same node. That node is the lowest common ancestor.
State that time complexity is O(h) and space is O(1). Discuss edge cases: p or q is the LCA, nodes at different depths, and tree with only one node.
AI-generated suggestions, not part of the candidate's original notes. May be inaccurate — verify before relying on them.