Find maximum product of two integers in an array

Given an array of integers, find the maximum product of two integers in an array. Return the elements of this array. If there are more than one satifying answer, pick the pair whose sum is greater than the other.

Example Solution

When the solution is called with the following input arr = [-10, -3, 5, 6, -2] it is expected to return the array [5, 6].

When we look for pairs whose product is the greater than others we come up with two pairs: -10 -3 and 5 6. Both of these pairs add up to 30. But since (-10-3) > (5+6), the correct answer is 5 6.

Contributed by Murat Sütunç