root of a binary search tree: for every node, all values in its left subtree are smaller than its own value and all values in its right subtree are larger. All values are distinct.
You also get two bounds, lo and hi. Return the sum of the values of all nodes that fall within the band from lo to hi, inclusive.
Think about how the ordering of the tree lets you skip branches that cannot contain any answer.root=tree_node([8, 3, 12, 1, 5, 10, 15]), lo=4, hi=11 → 23
The band [4, 11] contains 5, 8 and 10: 5 + 8 + 10 = 23.
root=tree_node([20, None, 30]), lo=1, hi=10 → 0
Every value is above 10, so the sum is empty: 0.
root=tree_node([8, 3, 12, 1, 5, 10, 15]), lo=4, hi=11
23
Run checks the first 3 tests in your browser. Submit checks all 53 tests on the server, hidden ones included.