Maximum path sum
Given a binary tree encoded as a level-order array (None marks a missing child; values may be negative), return the maximum path sum. A path is any sequence of nodes connected by edges where each node appears at most once; it does not need to pass through the root and need not be root-to-leaf. Use a post-order pass where each node returns the best downward gain (max single-branch contribution, clamped at 0) while a global best tracks the best 'arch' (left gain + node + right gain). Return the maximum path sum.
Implement
max_path_sum(level: list) → intExamples
in
[[-10,9,20,null,null,15,7]]out42What a strong answer looks like
State your approach and its time/space complexity out loud before you optimize. Handle the edge cases (empty input, duplicates, overflow), and say why you chose this over the brute force. Green tests are the floor, not the grade.
0:00 of about 30 min
solution.py
InputExpectedGot
[[-10,9,20,null,null,15,7]]42not run yetsample