@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 <[email protected]> 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 between this two leaves path, root is repeated.
> Hence actual sum is maxsum + secondMaxSum - root->val;
> This can be done by iterative inorder traversal of tehe tree
>
> T[n] - o[n]
> Space - o[n]
>
> --
> You received this message because you are subscribed to the Google Groups
> "Algorithm Geeks" group.
> To view this discussion on the web visit
> https://groups.google.com/d/msg/algogeeks/-/5Okg0EjlIAkJ.
>
> To post to this group, send email to [email protected].
> To unsubscribe from this group, send email to
> [email protected].
> For more options, visit this group at
> http://groups.google.com/group/algogeeks?hl=en.
>
--
You received this message because you are subscribed to the Google Groups
"Algorithm Geeks" group.
To post to this group, send email to [email protected].
To unsubscribe from this group, send email to
[email protected].
For more options, visit this group at
http://groups.google.com/group/algogeeks?hl=en.