Find pairs in array whose sum is already present

Given an array A of N distinct and positive elements, the task is to find number of unordered pairs whose sum already exists in given array.

Expected Complexity : n^2

CONSTRAINTS

1 <= N <= 1000
1 <= A[i] <= 10^6 + 5

SAMPLE INPUT

A : [ 3, 4, 2, 6 ,7]

SAMPLE OUTPUT

2

EXPLANATION

The pairs following the conditions are : 
(2,4) = 6,
(3,4) = 7
NOTE: You only need to implement the given function. Do not read input, instead use the arguments to the function. Do not print the output, instead return values as specified. Still have a doubt? Checkout Sample Codes for more details.
Start solving Find pairs in array whose sum is already present on Interview Code Editor
Sign Up
to access hints and editorial solutions for Find pairs in array whose sum is already present

Discussion


Loading...
Click here to start solving coding interview questions