Lowest Common Ancestor of a Binary Search Tree
Recognize the pattern
Brute force idea
If you approach Lowest Common Ancestor of a Binary Search Tree in the most literal way possible, you get this: Find paths from root to each node, compare paths for the last common node. Doesn't exploit the BST property. It is a fair place to begin because it matches the surface of the question, yet it does not capture the deeper structure that makes the problem simpler.
Better approach
The deeper shift in Lowest Common Ancestor of a Binary Search Tree is this: Walk from the root: if both values are smaller, go left. If both are larger, go right. When they split (one left, one right), the current node is the LCA. Once you hold onto the right piece of information from moment to moment, the problem feels less like trial and error and more like following a shape that was there all along.
Key invariant
At the center of Lowest Common Ancestor of a Binary Search Tree is one steady idea: In a BST, if p < node < q (or q < node < p), then node is where p and q diverge into different subtrees — that split point IS the LCA. No node deeper can be an ancestor of both. When you keep that truth intact, each local choice supports the larger solution instead of fighting it.
Watch out for
One easy way to drift off course in Lowest Common Ancestor of a Binary Search Tree is this: Using the generic binary tree LCA algorithm (recursive, ) when the BST property gives you a simpler solution. The BST ordering is a free guide. The fix is usually to return to the meaning of each move, not just the steps themselves.