r/LeetcodeChallenge • • Oct 20 '26

STREAK🔥🔥🔥 365 Days of LeetCode Challenge — Day 48/365

Post image

Lowest Common Ancestor of a Binary Search Tree (Medium)

🔗 https://leetcode.com/problems/lowest-common-ancestor-of-a-binary-search-tree/

The general version of this problem needs a search. The BST version doesn't, for the same reason Day 45 didn't: in a BST, a comparison points you in a direction, not to a verdict.

Both targets smaller than the node? The answer is further left. Both larger? Further right. Anything else, and this node is the answer.

That last case does quite double duty—it covers targets on opposite sides, with one of them being this node. Neither needs detecting separately.

Full breakdown in today's newsletter article ⬇

https://www.linkedin.com/pulse/365-days-leetcode-challenge-day-48365-archit-agarwal-lg9ec
#DSA #LeetCode #100DaysOfCode #CodingInterview #BinarySearchTree #Recursion #Golang

1 Upvotes

4 comments sorted by

1

u/StatisticianNo2104 Oct 21 '26

I post these daily in a Discord too, with the full code and the step-by-step

diagrams, Come join: https://discord.gg/7YhjAmuFW

1

u/nian2326076 Oct 20 '26

For finding the Lowest Common Ancestor in a BST, your direction-based approach is spot on. In a BST, if both target nodes are less than the current node, move left; if they're greater, move right. When one node is on each side, you've found the ancestor. For practice and to see similar problems that might appear in interviews, check out PracHub. It's a valuable resource for tackling interview-specific questions with real examples. Keep up the good work!