Question: Upvotes will be given for correct solution! Given an array of distinct integers, find if there are two pairs (a, b) and (c, d) such

 Upvotes will be given for correct solution! Given an array of

Upvotes will be given for correct solution!

Given an array of distinct integers, find if there are two pairs (a, b) and (c, d) such that a+b=c+d, and a, b, c, and d are distinct elements. If there are multiple elements, the function should print all pairs that work. You may assume that for any pair (a, b), there is at most one other pair (c,d) that sums to a+b. Example: Input: [3, 4, 7, 1, 2, 8] Output: (3, 2) and (4,1) 1/5 (3, 7) and (2, 8) //10 (3, 8) and (4, 7) 1/11 (7, 2) and (1, 8) 1/9 Input: [65, 30, 7, 90, 1, 9, 8] Output (nothing): // Prints out all different pairs in input_vec that have same sum. 1/ Expected Runtime: 0(2) void two-pair_sums (const vector (int> &input_vec, ostream& out)

Step by Step Solution

There are 3 Steps involved in it

1 Expert Approved Answer
Step: 1 Unlock blur-text-image
Question Has Been Solved by an Expert!

Get step-by-step solutions from verified subject matter experts

Step: 2 Unlock
Step: 3 Unlock

Students Have Also Explored These Related Databases Questions!