FastPrepUnique Pairs With Target Sum
Problems/Unique Pairs With Target Sum

Unique Pairs With Target Sum

Amazon logoAmazon● EasyFULLTIMEPHONE SCREEN
QuestionFunctionExamplesConstraints

Problem statement

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.

More Amazon problems

  • Number of IslandsPHONE SCREEN · ONSITE INTERVIEW · Seen Nov 2026
  • Minimum Cost of Left and Right PropagationOA · Seen Nov 2026
  • 3SumPHONE SCREEN · Seen Nov 2026
See Amazon hiring insights
Saved
class Solution {
    public String[] solveUniquePairsWithTargetSum(String input) {
        // write your code here
    }

}
Checking account…