End of Year Sale: Use Coupon Code END2025 to Get Extra 25% Off.
max_sum to negative infinity.max_gain(node) that:
node is null (base case).node.max_sum with the maximum of max_sum and the sum of the node's value and gains from both subtrees.max_gain(root) to start the recursion.max_sum.