gdsc-gvp/DSA

MaxPath Sum in Binary Tree

Closed this issue · 4 comments

MaxPathSum in Binary Tree

Algorithm :

  1. we travel recursively to leaf nodes of tree
  2. declare a global variable max_ans
  3. for each node we calculate 4 values
    i. node value
    ii. node value + maxSumPath(node->left)
    iii. node value + maxSumPath(node->right)
    iv. node value + maxSumPath(node->left) + maxSumPath(node->right)
  4. find maximum value among these 4 and if this value greater than max then put it there

C++

  • C
  • C++
  • Java
  • Python

Additional context (OPTIONAL)

Add any other context or screenshots about the feature request here.

It's great having you contribute to this project

Welcome to the community 🤓

If you would like to continue contributing to open source and would like to do it with an awesome inclusive community, you should join our Discord STAR THE REPO

I am participating in Hacktober 2021

Please assign me this isssue

Go and raise issue there https://github.com/gdsc-gvp/Problem-Solving
and Bot message doesn't mean to work on PR!