Challenge 5: Find Two Pairs in an Array with an Equal Sum

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 string findPair(int[] arr, int size) 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 any two pairs in the array, which satisfies the above condition.

Input

This is an array of distinct integers and their size.

Output

This is a string containing two pairs (a, b) and (c, d), which satisfies a + b = c + d in {a,b}{c,d}format.

Sample input

arr = {3, 4, 7, 1, 12, 9}
size = 6

Sample output

{{4,12},{7,9}}

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