Range Sum of BST
Given the root of a binary search tree and two integers low and high, return the sum of the values of all nodes whose value lies in the inclusive range [low, high].
Open official problem prompt ↗Add up only the BST values that fall within a given inclusive interval.
Scanning a sorted card catalog for entries between two call numbers: once a card is below your low bound, you know everything to its left is even lower and skip that whole drawer.
- Input
- root = [10,5,15,3,7,null,18], low = 7, high = 15
- Output
- 32
- Why
- The in-range nodes are 7, 10, and 15, and 7 + 10 + 15 = 32.
The number of nodes is in the range [1, 2*10^4]1 <= Node.val <= 10^51 <= low <= high <= 10^5All Node.val are unique