Monday, February 20, 2012

Three integers sum in an array.

If you had to find all sets of three integers that summed up to a given value? How would you do this?


Code input/output:
int [] A = {5, 9, 2, 11, 3, 8, 15, 7, 4, 12, 1, 6};


Sorted Array A:


1 2 3 4 5 6 7 8 9 11 12 15 
triplets that sum to 12:
1:4:7
1:2:9
2:3:7
1:3:8
3:4:5
1:5:6
2:4:6


No comments:

Post a Comment