Answered step by step
Verified Expert Solution
Link Copied!

Question

1 Approved Answer

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

Step: 1

blur-text-image

Get Instant Access with AI-Powered Solutions

See step-by-step solutions with expert insights and AI powered tools for academic success

Step: 2

blur-text-image

Step: 3

blur-text-image

Ace Your Homework with AI

Get the answers you need in no time with our AI-driven, step-by-step assistance

Get Started

Students also viewed these Databases questions

Question

Explain all drawbacks of application procedure.

Answered: 1 week ago