Sunny, Can but can we modify this code to get the *node X and node Y*?.
On Wed, Jun 22, 2011 at 8:32 AM, Anantha Krishnan < ananthakrishnan....@gmail.com> wrote: > @sunny agrawal > *Thanks a lot.* > *Great code. I got the logic now.Thanks again.* > * > * > Thanks & Regards, > Anantha Krishnan > > On Tue, Jun 21, 2011 at 11:52 PM, sunny agrawal > <sunny816.i...@gmail.com>wrote: > >> see this >> * >> https://ideone.com/1ZtIq* >> >> >> On Tue, Jun 21, 2011 at 10:23 PM, Anantha Krishnan < >> ananthakrishnan....@gmail.com> wrote: >> >>> Thanks. >>> I expect more details in implementation point of view. >>> >>> Thanks & Regards, >>> Anantha Krishnan >>> >>> >>> On Tue, Jun 21, 2011 at 6:41 PM, sunny agrawal >>> <sunny816.i...@gmail.com>wrote: >>> >>>> @Piyush >>>> good to start with >>>> But i think a recursive O(n) is possible >>>> in downward calls pass sum from root to node >>>> and on return calls pass sum from leafs to root of each subtree and >>>> using this collective information updating a global ans max. >>>> >>>> >>>> >>>> On Tue, Jun 21, 2011 at 5:05 PM, Piyush Sinha <ecstasy.piy...@gmail.com >>>> > wrote: >>>> >>>>> i am assuming all nodes have positive values.. >>>>> >>>>> Keep a buffer of all the leaf nodes..take two leaf nodes and find the >>>>> LCA..compute sum from root to LCA and subtract it from the sum of nodes >>>>> from >>>>> root to the leaves...store all the sums and find maximum out of it.. >>>>> >>>>> On Tue, Jun 21, 2011 at 4:52 PM, Anantha Krishnan < >>>>> ananthakrishnan....@gmail.com> wrote: >>>>> >>>>>> Hi All, >>>>>> >>>>>> Given a binary tree, find 2 leaf nodes say X and Y such that F(X,Y) is >>>>>> maximum where F(X,Y) = sum of nodes in the path from root to X + sum of >>>>>> nodes in the path from root to Y - sum of nodes in the common path from >>>>>> root >>>>>> to first common ancestor of the Nodes X and Y. >>>>>> >>>>>> Any ideas. >>>>>> >>>>>> Thanks & Regards >>>>>> Anantha Krishnan >>>>>> >>>>>> -- >>>>>> You received this message because you are subscribed to the Google >>>>>> Groups "Algorithm Geeks" group. >>>>>> To post to this group, send email to algogeeks@googlegroups.com. >>>>>> To unsubscribe from this group, send email to >>>>>> algogeeks+unsubscr...@googlegroups.com. >>>>>> For more options, visit this group at >>>>>> http://groups.google.com/group/algogeeks?hl=en. >>>>>> >>>>> >>>>> >>>>> >>>>> -- >>>>> *Piyush Sinha* >>>>> *IIIT, Allahabad* >>>>> *+91-8792136657* >>>>> *+91-7483122727* >>>>> *https://www.facebook.com/profile.php?id=100000655377926 * >>>>> >>>>> -- >>>>> You received this message because you are subscribed to the Google >>>>> Groups "Algorithm Geeks" group. >>>>> To post to this group, send email to algogeeks@googlegroups.com. >>>>> To unsubscribe from this group, send email to >>>>> algogeeks+unsubscr...@googlegroups.com. >>>>> For more options, visit this group at >>>>> http://groups.google.com/group/algogeeks?hl=en. >>>>> >>>> >>>> >>>> >>>> -- >>>> Sunny Aggrawal >>>> B-Tech IV year,CSI >>>> Indian Institute Of Technology,Roorkee >>>> >>>> >>>> -- >>>> You received this message because you are subscribed to the Google >>>> Groups "Algorithm Geeks" group. >>>> To post to this group, send email to algogeeks@googlegroups.com. >>>> To unsubscribe from this group, send email to >>>> algogeeks+unsubscr...@googlegroups.com. >>>> 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 algogeeks@googlegroups.com. >>> To unsubscribe from this group, send email to >>> algogeeks+unsubscr...@googlegroups.com. >>> For more options, visit this group at >>> http://groups.google.com/group/algogeeks?hl=en. >>> >> >> >> >> -- >> Sunny Aggrawal >> B-Tech IV year,CSI >> Indian Institute Of Technology,Roorkee >> >> -- >> You received this message because you are subscribed to the Google Groups >> "Algorithm Geeks" group. >> To post to this group, send email to algogeeks@googlegroups.com. >> To unsubscribe from this group, send email to >> algogeeks+unsubscr...@googlegroups.com. >> 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 algogeeks@googlegroups.com. > To unsubscribe from this group, send email to > algogeeks+unsubscr...@googlegroups.com. > 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 algogeeks@googlegroups.com. To unsubscribe from this group, send email to algogeeks+unsubscr...@googlegroups.com. For more options, visit this group at http://groups.google.com/group/algogeeks?hl=en.