Sponsored
Sponsored
Use these hints if you're stuck. Try solving on your own first.
What information do we need to calculate the average? We need the sum of the values and the number of values.
Create a recursive function that returns the size of a node’s subtree, and the sum of the values of its subtree.