Maximum Path Sum in Binary Tree (LeetCode 1249 / LeetCode 124)
Asked in the Loop (Code 1 or Code 2) stage. Reported as one of the coding problems asked during the loop.
Implement max_path_sum(root). The input is a non-empty binary tree represented as nested arrays [value, left, right], where a missing child is null. Return the maximum sum of any non-empty path. A path follows parent-child edges, may start and end at any nodes, and cannot revisit a node.
Function signature: def max_path_sum(root):
Return one integer.
def max_path_sum(root):