I found the solution to this problem in the
old leet code discuss forum.
I don't understand this line of code:
csum = max(node->val, max(node->val + lsum, node->val + rsum));
Why do we need to check if current node is greater than the sum of itself and its left and right subtree? Is it because a binary tree can contain negative numbers? If it contained only positive numbers, that check would be unnecessary, right? Or am I completely wrong here?