Dsa
Binary Search Tree
Easy
The Garden Moisture Path
A smart garden has sensors laid out in a BST based on their moisture threshold. Given two sensor thresholds A and B, find the sum of all moisture thresholds along the unique path between sensor A and sensor B in the BST. You may assume both A and B exist in the tree.
Example:
Input:
10 5 15 3 7 13 18
7 18
Output: 50
Explanation: LCA of 7 and 18 is 10. Path: 7 -> 5 -> 10 -> 15 -> 18. Sum: 7+5+10+15+18 = 50.
Key concepts
binary_search_treelowest_common_ancestorpath_sum
Practise this out loud — free
Start a mock interview on THIS exact question — a voice AI interviewer opens with it, pushes back like a real onsite, then hands you an instant scorecard.
🎙 Practise this question now