Re: [algogeeks] Re: max sum b/w 2 leaf nodes in a binary tree

2012-08-29 Thread kunal rustgi
@navin it is not necessary that path b/w two leaves always pass thru root. On Wed, Aug 29, 2012 at 1:15 AM, Navin Gupta wrote: > I think the path between two leaves always passes thru root. > Now we can keep track of root-to-leaf path whose sum is max and secondMax > among all sums. > Now betwe

Re: [algogeeks] Re: max sum b/w 2 leaf nodes in a binary tree

2012-08-29 Thread atul anand
@navin : /* *I think the path between two leaves always passes thru root.* */ not alwayzz..consider a case where there are 2 leaf node on left side of the tree. 1 / 5 / \ 10 15 ans :30 ( 5,10,15) root(1) is not included. On Wed, Aug 29, 2012 at 1:15 AM, Navin Gupta wrote: >

[algogeeks] Re: max sum b/w 2 leaf nodes in a binary tree

2012-08-28 Thread Navin Gupta
I think the path between two leaves always passes thru root. Now we can keep track of root-to-leaf path whose sum is max and secondMax among all sums. Now between this two leaves path, root is repeated. Hence actual sum is maxsum + secondMaxSum - root->val; This can be done by iterative inorder tr