Challenge: Find Two Pairs in an Array Such That a+b = c+d

If you are given an array, can you find two pairs such that their sum is equal?

Problem Statement

In this problem, you have to implement the findPair() function which will find two pairs [a, b] and [c, d] in an array such that:

a+b=c+da+b = c+d

You only have to find the first two pairs in the array which satisfies the above condition. Assume that the input array does not contain any duplicates.

Input

An array of distinct integers.

Output

An array containing two pairs (a, b) and (c, d) which satisfy a + b = c + d

Sample Input

var my_list = [3, 4, 7, 1, 12, 9]

Sample Output

[[4,12],[7,9]]

Level up your interview prep. Join Educative to access 70+ hands-on prep courses.