Loading...
Loading...
Loading...
Replace every key of a binary search tree by the sum of all keys that are greater than or equal to it. Print the new keys in inorder, separated by spaces.
Example 1
Input
8 3 10 1 6 # 14 # # 4 7 13
Output
66 65 62 58 52 45 37 27 14
Example 2
Input
2 1 3
Output
6 5 3
Try the problem first. Open one hint at a time.
Visit the keys from largest to smallest: right subtree, node, left subtree.
Keep a running total and use it as the new value.
Write your Python code, run it on the examples and submit it to hidden tests.
Solve in the editor