DoorDash | Coding | Max Tree Path Sum
Anonymous User
6623
Oct 09, 2021

From an onsite

Given a binary tree, find the maximum path sum from any two "alive nodes" within the tree. We can assume a node is an alive node if and only if it is a leaf node, indicated by an asterisk below.

     5
    /  \
   2    0
  /    /  \
*25   *14  *15

47 = 25 + 2 + 5 + 15

Follow - up
What if any nodes in the tree can be alive instead of just the leaves?

Comments (16)