Sponsored
Sponsored
Use these hints if you're stuck. Try solving on your own first.
Can you find the sum of values and the number of nodes for every sub-tree ?
Can you find the sum of values and the number of nodes for a sub-tree given the sum of values and the number of nodes of it's left and right sub-trees ?
Use depth first search to recursively find the solution for the children of a node then use their solutions to compute the current node's solution.