← All questions
HardCoding
Binary Tree Maximum Path Sum
Asked at
Qualcomm
DoorDash
Microsoft
Nutanix
Oracle
1Give yourself 5 minutes
2Answer out loud, not in your head
3Then compare with the answer below
0
Stuck? Show a way to structure it+
- 01Define DFS(node) as the best downward path gain that can be extended by the parent.
- 02Clamp each child gain at zero because a negative branch should be excluded.
- 03Use both child gains to update the best complete path passing through the current node.
- 04Return the node value plus only the better child gain to preserve a single path.
Reference answer
Then expect these follow-ups
How would you also reconstruct the nodes on the maximum path?
Tests: state reconstruction
Why can the value returned to the parent include only one child?
Tests: correctness reasoning
Free to read · better with Enzo
Practice this out loud with Enzo
Enzo runs it as a mock interview, pushes back with follow-ups, and grades you on the rubric.
Next question