← 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
Hiring now
Qualcomm has 707 open roles right now
Also hiring: DoorDash, Nutanix
landed applies to roles like these for you, on each company’s own site, with answers written for the role.
Get 5x interviews10 free auto-applies. No card.
CAD Engineer – AMS & Custom Layout
Toronto, Ontario, Canada
GPU Design Verification Engineer
Santa Clara, California, United States of America
Senior Product & Test Engineer, RF & Mixed-Signal Semiconductors
Singapore, Central Singapore, Singapore
Next question