Pair Sum Problem Statement
You are provided with an array ARR
consisting of N
distinct integers in ascending order and an integer TARGET
. Your objective is to count all the distinct pairs in ARR
whose sum equals TARGET
.
Note:
- Pair
(x, y)
and Pair(y, x)
are considered as the same pair. - If no such pair exists with a sum equal to
'TARGET'
, then return -1.
Example:
Input:
ARR = [1, 2, 3], TARGET = 4
Output:
1
Explanation:
There exists only one pair in ARR
with a sum of 4, which is (1, 3)
. (1, 3)
and (3, 1)
are counted as a single pair.
Constraints:
1 ≤ T ≤ 100
2 ≤ N ≤ 5000
1 ≤ ARR[i], TARGET ≤ 105
- The array
ARR
contains distinct elements.
Be the first one to answer
Add answer anonymously...
Top HashedIn by Deloitte SDE-2 interview questions & answers
Popular interview questions of SDE-2
Top HR questions asked in HashedIn by Deloitte SDE-2
>
HashedIn by Deloitte SDE-2 Interview Questions
Stay ahead in your career. Get AmbitionBox app
Helping over 1 Crore job seekers every month in choosing their right fit company
65 L+
Reviews
4 L+
Interviews
4 Cr+
Salaries
1 Cr+
Users/Month
Contribute to help millions
Get AmbitionBox app