Hi,
*TSUM:*
This is also a brute-force approach..
Pls correct me if i m wrong
Algorithm:
1.sort the array
2.find the sum of the three min elements -> sum_min
3.find the sum of the three max elements -> sum_max
4.for each value in [sum_min,sum_max]
binary search for the triplet
int count=0;
Arrays.sort(a);
int sum_min=a[0]+a[1]+a[2];
int sum_max=a[a.length-1]+a[a.length-2]+a[a.length-3];
for(int sum=sum_min;sum<=sum_max;sum++)
{
for(int i=0;i<a.length;i++)
{
for(int j=i+1;j<a.length;j++)
{
if(Arrays.binarySearch(a,sum-a[i]-a[j]) > j)
{
count++;
}
}
}
System.out.println(sum+":"+count);
count=0;
}
--
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.