Please clear the Doubt From Video

Only the globalmax should give us the ans na?
As the thing which the function returns is
max of left and right
not
max of left + max of right

Please tell me as i am confused

@Ramitgoel
See here two things are maintained in the function, one thing is current answer which is possible if we take current node as root node.
second thing is if we take this subtree as the part of the bigger tree then that it will contribute something to that.

So in global variable we are storing the first thing, but here the function is recursive so it needs to return something which is useful for its parent, who has called this subtree, so it return second thing.

I hope it clears your doubt. Feel free to ask!
If you understood it now then please mark this doubt as resolved

@sanyamsinghalmnnit
so in the end both will contain same value ?

@Ramitgoel No the end global variable will contain the answer, the function will just return the possible answer when we take root in the path of maximum answer.

1 Like

yeah i also thought it ,
Thanks a lot !!

@Ramitgoel please don’t forget to mark the doubt as resolved.