Maximum Sum BST in Binary Tree
Hard · Binary Search Trees · about 30 minutes
Asked at Amazon, Google, Microsoft, ByteDance.
Return the maximum sum of the keys of any subtree of a binary tree that is also a binary search tree (strictly smaller left, strictly larger right). The empty tree counts with sum 0, so the answer is never negative.