Given a binary tree, find the lowest common ancestor (LCA) of two given nodes p and q. The LCA is defined as the lowest node in the tree that has both p and q as descendants (a node can be a descendant of itself).
root = [3,5,1,6,2,0,8,null,null,7,4], p=5, q=13root = [3,5,1,6,2,0,8,null,null,7,4], p=5, q=45root==null → return null; root==p or root==q → return rootleft = lca(root.left, p, q)right = lca(root.right, p, q)left != null && right != null → return root (THIS is LCA!)Each call returns the "found" node if it found p or q (or their ancestor), or null if neither was found. At any node: if both left and right calls returned non-null, it means p is in one subtree and q is in the other — so this node is the LCA. If only one side is non-null, that side already contains both targets (one is an ancestor of the other), so we propagate that result upward.