Medium

Two Sum Pairs

Description

Given an array of integers and a target sum, return all unique pairs of numbers that add up to the target sum. Each pair in the output should be sorted in ascending order, and the pairs themselves should be sorted in ascending order (by first number, then second number if first number is equal).

If no pairs are found, return an empty array.

Requirements:

  • Don't use the same element twice for a pair
  • Each pair should be sorted (smaller number first)
  • The output array should be sorted by the first number of each pair
  • Remove any duplicate pairs
  • Return empty array if no pairs are found

Example Usage

Input: numbers = [1, 2, 3, 4, 5], target = 7
Output: [[2, 5], [3, 4]]

window code 2Test Cases

Input:

[
  1,
  2,
  3,
  4,
  5
]

Expected Output:

"[[2,5],[3,4]]"