Dsa
Two Pointers
Hard
Pairs of Targets
You need to find all unique pairs of integers in a given list that add up to a specified target. The integers in the list can contain duplicates, but the output should consist of unique pairs represented in ascending order. Return the list of pairs sorted by their first element.
Input format:
- The first line contains two integers n (1 ≤ n ≤ 10^5) and target (|target| ≤ 10^9), where n is the number of integers.
- The second line contains n space-separated integers (|arr_i| ≤ 10^9) representing the list of integers.
Output format:
- Output the sorted unique pairs as a list of space-separated strings for each pair in the format "(a,b)".
Example:
Input:
5 6
1 5 3 2 4
Output:
(1,5) (2,4)
Key concepts
two_pointersarrayssorting
Practise this out loud — free
Start a mock interview on THIS exact question — a voice AI interviewer opens with it, pushes back like a real onsite, then hands you an instant scorecard.
🎙 Practise this question now