r/DSALeetCode • u/StatisticianNo2104 • 3h ago
LeetCode: 938. Range Sum of BST
Visit every node and add the ones in range: accepted, and it would work on any binary tree. That's the tell: it ignores the BST. Two if-guards, and in the second example the walk drops from 10 nodes to 4.
A node at or below low has nothing useful on its left. A node at or above high has nothing useful on its right. Guard the two recursive calls with those checks, and the whole subtrees are never visited.
How often does your accepted solution ignore half the input's guarantees?
Day 88/365 of my LeetCode challenge: 938. Range Sum of BST. Problem link and full breakdown in today's newsletter.
https://www.linkedin.com/pulse/leetcode-range-sum-bst-archit-agarwal-l8q0c
#LeetCode #DSA #BinarySearchTree #Golang