Two Sum Pair Finding Task

Given an array of integers ARR of length N and an integer Target, your objective is to find and return all pairs of distinct elements in the array that sum up to the Target.

Input:

integer T
array length N, integer Target
array ARR of length N

Output:

All pairs of elements (a, b) such that a + b = Target
-1 -1 if no such pair exists

Example:

Input:
T = 1
N = 4, Target = 9
ARR = [2, 7, 11, 15]
Output:
2 7
Explanation:

The pair (2, 7) adds up to 9.

Constraints:

  • 1 <= T <= 100
  • 1 <= N <= 5000
  • -109 <= Target <= 109
  • -109 <= ARR[i] <= 109

Note:

Duplicate pairs are not allowed (e.g., (a, b) is the same as (b, a)). Each pair should be unique and can be printed in any order. Ensure not to use an element at an index more than once. The function to implement is already handled for output; focus on correctness.

AnswerBot
4d

Given an array of integers and a target integer, find and return all pairs of distinct elements that sum up to the target.

  • Iterate through the array and for each element, check if the difference betwee...read more

Help your peers!
Add answer anonymously...
UST Software Engineer Interview Questions
Stay ahead in your career. Get AmbitionBox app
qr-code
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

Made with ❤️ in India. Trademarks belong to their respective owners. All rights reserved © 2024 Info Edge (India) Ltd.

Follow us
  • Youtube
  • Instagram
  • LinkedIn
  • Facebook
  • Twitter