All Distinct Target-Sum Pairs
Updated
Problem statement
Given an array nums of nonnegative integers and a nonnegative integer target, return every distinct value pair whose sum is the target. Each pair must use two different input positions.
Write each pair as [smaller, larger], and return pairs in lexicographic order. Repeated index choices do not create repeated value pairs. A pair [x,x] requires at least two copies of x. Return an empty array when no pair exists.
Function
allUniquePairs(nums: int[], target: int) → int[][]Examples
Example 1
nums = [1,2,3,2,4,0]target = 4return = [[0,4],[1,3],[2,2]]The three distinct value pairs sum to 4. Two copies of 2 make [2,2] valid.
Example 2
nums = [1,1,1]target = 2return = [[1,1]]Repeated index choices do not create additional value-pair results.
Constraints
0 <= nums.length <= 100000.0 <= nums[i] <= 1000000000.0 <= target <= 2000000000.
Interview reports that mention this question
- Expedia Intern Final Round in 2020: 24 Experiences (Part 5 of 6)
- Expedia Intern Final Round in 2022: 15 Experiences (Part 3 of 6)
- Expedia Intern Final Round in 2023: 17 Experiences (Part 2 of 6)
- Expedia SWE Intern Final Round: 126 Experiences (Part 1 of 6)
- Expedia New Grad SDE Earlier Loops: 5 Experiences (Part 2 of 3)