Unique Pairs With Target Sum
Reported by candidates from Amazon's online assessment. Pattern, common pitfall, and the honest play if you blank under the timer.
The Amazon OA reported in May 2026 looks like a plain two-sum, and that's the trap. Duplicates in the array are what break the naive version. If you emit a pair for every index combo, 2,3 shows up twice in Example 1 and you fail. This is a unique-pairs problem: hash set or sort plus two pointers, with strict dedup on values, not indices. You also have to parse raw stdin yourself and print "None" when nothing matches. If you blank on the dedup logic mid-assessment, StealthCoder is the invisible safety net that reads the problem and hands you a working solution.
The problem
Complete the function below. The function receives the full standard input as a single string and returns the exact standard output lines. Problem Given an integer array and a target value, return all unique pairs whose sum equals the target. Each pair must be sorted in ascending order, and duplicate pairs must appear only once. Output the pairs in lexicographic order as a,b. If there are no valid pairs, output None. Function solveUniquePairsWithTargetSum(input: String) → String[] Complete solveUniquePairsWithTargetSum. It has one parameter, String input. The first line contains n target; the second line contains n integers. Return one output line per unique pair. Examples Example 1 input = "8 5\n1 4 2 3 3 2 0 5" return = ["0,5","1,4","2,3"] The pair 2,3 is output once even though both values appear multiple times. Example 2 input = "4 10\n1 2 3 4" return = ["None"] No pair sums to 10. Constraints Pairs are value pairs, not index pairs; duplicates in the input should not create duplicate output lines.
Reported by candidates. Source: FastPrep
Pattern and pitfall
Two clean routes. Route one: sort the array, run two pointers from both ends. When the sum matches, record the pair, then move left past all equal values and right past all equal values. That skip step is the whole trick. Skip it and you output duplicates. Route two: keep a set of seen numbers and a set of pairs, and for each x check if target - x was seen, then add (min, max) to the pair set. Sort the pairs lexicographically at the end. The pitfalls: comparing pairs as strings instead of numbers, which misorders negatives and multi-digit values. Another is the case where both values are equal, like 2 and 2 for target 4, which needs two copies in the input. The two-pointer version handles it naturally. Parse n and target from line one, numbers from line two, and return ["None"] when empty. If the parsing or skip logic slips under pressure, StealthCoder is your hedge on the live OA.
If this hits your live OA and you blank, StealthCoder solves it in seconds, invisible to the proctor.
You can drill Unique Pairs With Target Sum cold, or you can hedge it. StealthCoder runs invisibly during screen share and surfaces a working solution in under 2 seconds. The proctor sees the IDE. They don't see what's behind it. Built by an Amazon engineer who would have shipped this the night before his JPMorgan OA if he'd had it.
Get StealthCoderRelated leaked OAs
You've seen the question.
Make sure you actually pass Amazon's OA.
Amazon reuses patterns across OAs. Built by an Amazon engineer who would have shipped this the night before his JPMorgan OA if he'd had it. Works on HackerRank, CodeSignal, CoderPad, and Karat.
Unique Pairs With Target Sum FAQ
What's the trick in Unique Pairs With Target Sum?+
Dedup by value, not index. Sort the array, use two pointers, and after recording a match skip every repeated value on both sides. Alternatively store normalized (min, max) pairs in a set. Either way, each value pair prints exactly once.
How hard is this Amazon OA question really?+
Easy to medium. The core is two-sum, but the dedup rules, stdin parsing, and ordering requirements are where people lose points. If you've written two-pointer code with duplicate skipping before, it's a ten-minute problem.
How should I sort the output pairs?+
Sort numerically by first element, then second. Don't sort the formatted strings, because "-1,5" and "10,2" order wrongly as text. Sort the numeric tuples first, then format each as a,b at the end.
What about pairs where both numbers are the same?+
A pair like 2,2 for target 4 is valid only if the value appears at least twice. Two pointers handles this automatically since the pointers sit on different indices. With a hash approach, check seen before adding the current value.
How do I prep for this in 48 hours?+
Write two-sum, then 3-sum style duplicate skipping, then practice reading n and target from a raw input string. Test the empty case so you print None. Also test negatives and repeated values before you submit.