The tests write a tree as a level-order list (row by row, left to right) with None for a missing child: [3, 9, 20, None, None, 15, 7] is a root 3 with children 9 and 20, where 20 has children 15 and 7. All trees in this topic that are called BSTs have different values.
Return the sum of the values in the tree that are between low and high (both included).
For [10, 5, 15, 3, 7, None, 18], low = 7 and high = 15 the answer is 32 (7 + 10 + 15).
Example 1
Input:
range_sum_bst(root, 7, 15) # root = [10, 5, 15, 3, 7, None, 18]
Output:
32
Example 2
Input:
range_sum_bst(root, 6, 10) # root = [10, 5, 15, 3, 7, 13, 18, 1, None, 6]
Output:
23
0 <= number of nodes <= 1000000 <= low <= high <= 10**9No results yet
Run your code to check it against the examples, or submit to run every test.