Dataford
Interview QuestionsInterview GuidesExperiencesMock InterviewsPricing
Get started

Two-Sum Non-Repeating Pairs

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

Your question is Two-Sum Non-Repeating 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

A Tanium endpoint analysis routine receives an unsorted array of integer measurements and a target value. Return every distinct pair of values whose sum equals the target.

A pair is identified by its values, not by the indices that produced it. Duplicate values in the input must not cause duplicate pairs in the output. Within each pair, place the smaller value first. Return the collection of pairs sorted lexicographically by first value, then second value. If no pair exists, return an empty list.

Formal Specification

Implement find_unique_pairs(nums, target).

  • Input: nums, a list of integers, and target, an integer.
  • Output: A list of two-element lists. Each inner list contains one unique pair whose values sum to target.
  • Each array element can be used only with a different occurrence. For example, [3] cannot produce [3, 3], but [3, 3] can.

Constraints

  • 0 <= len(nums) <= 10^5
  • -10^9 <= nums[i] <= 10^9
  • -10^9 <= target <= 10^9
  • Each output pair contains distinct array occurrences
  • Pairs must be unique and sorted lexicographically

Function Signature

def find_unique_pairs(nums, target):
Your solutionPython 3
You need to log in / sign up to run or submit.
Run your code to see test output