Dataford
Interview QuestionsInterview GuidesExperiencesMock InterviewsPricing
Get started

Find Target Sum Pairs

EasyPython00:00
Practice interviewer
In session
5 left
00:00

Your question is Find Target Sum Pairs. Start with the requirements on the right.

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.

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):
Your solutionPython 3
You need to log in / sign up to run or submit.
Run your code to see test output