Maximum Sum of the tree | CODING INTERVIEW ARCHIVES
Given a binary tree, where the value of each node is non-negative, you have to find the maximum sum which is formed using the nodes. But condition here is that, if you consider a node into your sum calculation then you can not take it's direct parent (if any) as well as it's direct children (if any).
Approach:
It may seem, at first, a problem of level-order traversal. But it's not. To counter that, let's take an example:
Approach:
It may seem, at first, a problem of level-order traversal. But it's not. To counter that, let's take an example:
Read full article from Maximum Sum of the tree | CODING INTERVIEW ARCHIVES
No comments:
Post a Comment