Find all couples that sums to a number in an integer array
Sigiloso
This solution is for the case of combinations i.e. we don't care about order in pairs: 1. Sort the integer array (Yeah it can be sorted even if there are negative numbers lol). 2. Copy the integers into a set Intset (sets aren't necessarily ordered so it needs to be a separate copy). 2. Create a set for repeating numbers RNset and a list for pairs. 3. Iterate through the array. For each number i: I. Check if i >= the number n. If so, break. II. Check if i is in RNset. If in RNset, continue to the next iteration. III. If not, subtract i from the number n to obtain a result r. III. Check if r is in Intset. If it is, add the pair (i, r) to the list. If not, continue to the next iteration. IV. Add r to RNset.