Loading...
Loading...
Loading...
A binary search tree holds order numbers. Given low and high, print how many keys are between them, inclusive, and the sum of those keys.
Example 1
Input
8 3 10 1 6 # 14 # # 4 7 13 4 10
Output
5 35
Example 2
Input
8 3 10 1 6 # 14 # # 4 7 13 20 30
Output
0 0
Try the problem first. Open one hint at a time.
Skip the left subtree when the node is not larger than low, and the right subtree when it is not smaller than high.
A generator of the keys in range feeds len and sum.
Write your Python code, run it on the examples and submit it to hidden tests.
Solve in the editor