This is one of the hardest tree problems and a favorite in interviews. It combines the "track global optimum during DFS" pattern with careful handling of negative values.
Enable JavaScript for the full StreamPrep guide.