Why we are returning max(ls, max(rs, 0)) + root->val ?
Also, where we have considered the case in which path is not including a root node. Since in all the four cases we have taken root->val.
Why we are returning max(ls, max(rs, 0)) + root->val ?
Also, where we have considered the case in which path is not including a root node. Since in all the four cases we have taken root->val.
@vaishnavtannu return max(ls,max(rs,0))+root->data;
max(ls,max(rs,0))
this part will consider the max from ls, rs and 0, and we add it to root->data and return it.
This is the recursive work we have to do in order to calculate the sum path.
how will a path exist without the root node? The paths that do exist without the root node have already been taken care of by recursive calls.
I hope I’ve cleared your doubt. I ask you to please rate your experience here
Your feedback is very important. It helps us improve our platform and hence provide you
the learning experience you deserve.
On the off chance, you still have some questions or not find the answers satisfactory, you may reopen
the doubt.