Pair Sum Problem Statement
Given an integer array ARR
of size N
and an integer S
, your task is to return a list of all pairs of elements such that the sum of each pair equals S
.
Input:
The first line contains two space-separated integers N
and S
, representing the size of the array and the target sum.
The second line contains N
space-separated integers, representing the elements of the array ARR
.
Output:
For each pair, print a line containing two space-separated integers indicating the numbers in the pair. Pairs should be sorted in non-decreasing order based on the first element, and if two pairs have the same first element, the pair with the smaller second element should come first.
Example:
Input:
N = 5, S = 5
ARR = [1, 2, 3, 4, 2]
Output:
1 4
2 3
2 3
Constraints:
- 1 <= N <= 103
- -105 <= ARR[i] <= 105
- -2 * 105 <= S <= 2 * 105
- Time Limit: 1 sec
Note:
Ensure the pairs are sorted as mentioned and implement the function without handling output print operations as this is pre-managed.

AnswerBot
4mo
The task is to find pairs of elements in an array that sum up to a given target value.
Iterate through the array and for each element, check if the complement (target - current element) exists in a has...read more
Help your peers!
Add answer anonymously...
Amazon Software Developer interview questions & answers
A Software Developer was asked 1mo agoQ. Could you describe the process for designing a data structure that allows for al...read more
A Software Developer was asked 1mo agoQ. What is HTML?
A Software Developer was asked 1mo agoQ. What is MySQL?
Popular interview questions of Software Developer
A Software Developer was asked 1mo agoQ1. Could you describe the process for designing a data structure that allows for al...read more
A Software Developer was asked 1mo agoQ2. What is MySQL?
A Software Developer was asked 1mo agoQ3. What is Java?
Top HR questions asked in Amazon Software Developer
A Software Developer was asked 1mo agoQ1. Tell me about a time you had to get to the root cause of a problem
A Software Developer was asked 5mo agoQ2. What are the short-term and long-term goals for the team or organization?
A Software Developer was asked 5mo agoQ3. Why do you want to work at Amazon?
Stay ahead in your career. Get AmbitionBox app


Trusted by over 1.5 Crore job seekers to find their right fit company
80 L+
Reviews
10L+
Interviews
4 Cr+
Salaries
1.5 Cr+
Users
Contribute to help millions
AmbitionBox Awards
Get AmbitionBox app

