Heaviest path in a tree
A path in a binary tree is a chain of nodes in which each one is joined to the next by a parent-child link and no node appears twice. It may start and end anywhere, need not pass through the root, and may be a single node. Write max_path_sum(root): return the largest sum of values over all paths. The tree has at least one node and values can be negative. Each TreeNode has val, left and right.
The tests call the provided run_max_path_sum(values), where values lists the tree level by level with null for a missing child: [1, null, 2, 3] is a root 1 with only a right child 2, whose left child is 3.
Examples
run_max_path_sum([2,7,4])→13run_max_path_sum([-6,5,9,null,null,8,3])→20run_max_path_sum([-4])→-4