I have a code, given an array and target sum my code returns pair of two integers which add up to the sum. The Python function is as follows
def pairSum2(arr, k):
if len(arr)<2:
return
seen=set()
output=set()
for num in arr:
target=k-num
if target not in seen:
seen.add(num)
else:
output.add( (min(num, target), max(num, target)) )
print ('\n'.join( map(str, list(output)) ))
I have to modify it such that given the sum, find out maximum possible combinations in the array which are <= sum:
- no more than two numbers can be included in each combination, find out how many such combinations can be made.
I have referred subset sum problem Subset Sum algorithm. How ever this algorithm prints all the subsets which add upto the sum. I am allowed to take <=two numbers at a time.