Sponsored
Use these hints if you're stuck. Try solving on your own first.
Can we reuse previously calculated information?
How can we calculate the sum of the current subtree using the sum of the child's subtree?
Solve with full IDE support and test cases