Maximum sum path from any node to node

si r ishme hum ye kyu nahi maanta leftsubtree or rightsubtree itna badiya hai ki ushe root ko add karne ki jaaroorat hi nahi

ho sakta h to choose either left or right subtree
when u have a tree like
image
answer will be 3

1 Like

Mam but in vedio sir didnt do it that way

They just consider max(max(l,r.,0)+root)

the variable max_top stores the max value we have encountered uptil now ( it may be just 1 node , or formed from multiple nodes) here just node 3 is contributing to max sum hence 3 is returned

mam ek ye bhi toh case ho sakhta hai ki previous wala global maximum main agar mai naya sum ko add karu toh woh ushe zyaada banna de

agar left , ya right hoga to vo automatically add ho jayega

and then max will get calculated