Fundamentals/Subtree with Maximum Average
← PrevNext →
Given a tree, find the subtree with the maximum average value. Return the root's value of the subtree. Note that the tree can have any number of children.
Example 1
Input
Output: 12
Explanation
The sum of each subtree:
The subtree's maximum average is 9.3, and the root of the subtree with the maximum average is the node with value 12. Thus, we return 12.