Re: [algogeeks] Re: |a-b| + |b-c| + |c-a|

2011-08-18 Thread Anantha Krishnan
Let, min_dif=INT_MAX 1.Sort the N arrays A,B,C. 2.Find the minimum and maximum of A[0],B[0],C[0]. 3.Take the difference between MAX-MIN values. 5.If the difference is less than min_dif then update min_dif and save all n values. 6.Now increment the index of the array which contains

Re: [algogeeks] Re: |a-b| + |b-c| + |c-a|

2011-08-18 Thread MAC
as per my understanding , you are increasing the minimum value so that it reaches closer to the maximum others that we are not moving right now . Why are you not moving the maximum instead ? basically i need the reason why you are doing so .. thanks --mac; On Thu, Aug 18, 2011 at 12:08 PM,

Re: [algogeeks] Re: |a-b| + |b-c| + |c-a|

2011-08-18 Thread Anantha Krishnan
If we move the maximum then difference will get larger but our aim is to minimize the difference. Thanks Regards, Anantha Krishnan On Thu, Aug 18, 2011 at 1:01 PM, MAC macatad...@gmail.com wrote: as per my understanding , you are increasing the minimum value so that it reaches closer to the

Re: [algogeeks] Re: |a-b| + |b-c| + |c-a|

2011-08-18 Thread MAC
in the example below , answer shd be 0 , . by your apraoch this is not commig 10,25,35 10,25,30 5 ,6,25,30 On Thu, Aug 18, 2011 at 1:08 PM, Anantha Krishnan ananthakrishnan@gmail.com wrote: If we move the maximum then difference will get larger but our aim is to minimize the

Re: [algogeeks] Re: |a-b| + |b-c| + |c-a|

2011-08-18 Thread Anantha Krishnan
Yes with my approach answer will be 0. Please check here http://ideone.com/Q4ivj. Thanks Regards, Anantha Krishnan On Thu, Aug 18, 2011 at 1:33 PM, MAC macatad...@gmail.com wrote: in the example below , answer shd be 0 , . by your apraoch this is not commig 10,25,35 10,25,30 5

[algogeeks] Re: |a-b| + |b-c| + |c-a|

2011-08-18 Thread WgpShashank
Hey Mac, Coded it Sometimes back , Have a Look(i know its naive way :D) so let me know if anything wrong , we can use Min-Heap to make solution efficient isn't it ? http://shashank7s.blogspot.com/2011/06/given-3-arrays-pick-3-nos-one-from-each.html Thanks Shashank Mani Computer Science

[algogeeks] Re: |a-b| + |b-c| + |c-a|

2011-08-17 Thread MAC
any suggestion on how to approach this problem ?? On Wed, Aug 17, 2011 at 10:37 PM, MAC macatad...@gmail.com wrote: Given n arrays, find n number such that sum of their differences is minimum. For e.g. if there are three arrays A = {4, 10, 15, 20} B = {1, 13, 29} C = {5, 14, 28} find