FreeCareerPath
Build the PrimitiveHard

Binary Tree Maximum Path Sum

Write `max_path_sum(root)` returning the largest sum along any path between two nodes. The path follows parent-child edges, need not touch the root, and must contain at least one node. Values may be negative. Same shape as Diameter: the recursion returns the best *downward* gain to its parent, while a running best records the path that turns at this node (`node.val + left + right`). Clamp a negative gain to zero — refusing a subtree is always allowed. Initialise the best to negative infinity, not zero, or an all-negative tree returns 0.

What to expect: A timer starts when you begin. Edit the starter code, run it against the test suite as many times as you like, then finish when you're done. The reference solution and interviewer follow-up questions unlock only after you finish.

Log in to start this session

Timed sessions and your results for "Binary Tree Maximum Path Sum" are saved to your account — logging in takes a few seconds.

Binary Tree Maximum Path Sum — FreeCareerPath