Question: C++ Only WAP that takes n integer numbers and an integer k, and how many pairs of numbers in the array which sums to k.

C++ Only

WAP that takes n integer numbers and an integer k, and how many pairs of numbers in the array which sums to k. You have to do it inside the Merge Sort function, divide and conquer fashion in O(nlogn).

Sample input

Sample output

5

6 1 3 2 4

5

2

6

5 6 7 8 0 1

16

0

In sample 1, k = 5. a[1] + a[4] = 1 + 4 = 5 and a[2] + a[3] = 3 + 2 = 5. So the output is 2.

In sample 2, k = 16 and no pair of numbers sum to 16. It is not allowed to use the same index twice. For example a[3] + a[3] = 8 + 8 = 16 but we cannot use index 3 twice.

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!