
In a Meta interview setting, you are given the root of a binary tree and two integers low and high. Return the sum of all node values v such that low <= v <= high.
For this problem, assume the input tree is a binary search tree (BST). Use that property to avoid exploring subtrees that cannot contain valid values.
root: root node of a BST, or nulllow: integer lower boundhigh: integer upper bound[low, high]Example 1
root = [10,5,15,3,7,null,18], low = 7, high = 15327, 10, and 15, so the sum is 32.Example 2
root = [10,5,15,3,7,13,18,1,null,6], low = 6, high = 10236, 7, and 10, so the sum is 23.0 <= number of nodes <= 2 * 10^41 <= Node.val <= 10^51 <= low <= high <= 10^5root = [10,5,15,3,7,null,18], low = 7, high = 15Output32WhyThe values within the inclusive range are 7, 10, and 15.root = [10,5,15,3,7,13,18,1,null,6], low = 6, high = 10Output23WhyThe values within the range are 6, 7, and 10, which sum to 23.0 <= number of nodes <= 2 * 10^41 <= Node.val <= 10^51 <= low <= high <= 10^5The input tree is a valid BSTdef range_sum_bst(root, low, high):