Dataford
Interview QuestionsInterview GuidesExperiencesMock InterviewsPricing
Get started
Find Target Sum Pairs
00:00
5 left

Find Target Sum Pairs

EasyPython

Problem

In a Meta-style coding screen, you are given a list of integers and a target value. Return all unique pairs of values whose sum equals the target.

A pair should be included only once, regardless of ordering. For example, (1, 5) and (5, 1) represent the same pair. If a value must be used twice, it must appear at least twice in the input.

Formal Specification

  • Input: nums — a list of integers, and target — an integer
  • Output: a list of unique pairs, where each pair is a list [a, b] such that a + b == target and a <= b
  • Return the pairs sorted in ascending order by value.

Constraints

  • 0 <= len(nums) <= 10^5
  • -10^9 <= nums[i] <= 10^9
  • -10^9 <= target <= 10^9
  • Return unique value pairs only
  • Each returned pair must be in ascending order

Function Signature

def find_target_pairs(nums, target):
Interviewer

Your question is Find Target Sum Pairs. Start with the requirements in the Question tab.

Run and submit as often as you like. When you're ready, talk me through your approach or go straight to the code.

You need to log in / sign up to run or submit.
CodePython 3
You need to log in / sign up to run or submit.Ln 2
Run your code to see test output here.