Dataford
Interview QuestionsInterview GuidesExperiencesMock InterviewsPricing
Get started

Pairs With Sum Equals X

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

Your question is Pairs With Sum Equals X. 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 Ness Digital Engineering analytics pipeline receives an array of integer measurements and a target value x. Return every unique pair of values whose sum equals x.

Each pair must be ordered from smaller to larger, duplicate pairs must be removed, and the final list must be sorted lexicographically. A value may be used twice only when it appears at least twice in the input array. If no pair exists, return an empty list.

Formal Specification

Implement find_pairs(nums, x).

  • Input: nums, a list of integers, and x, an integer target.
  • Output: A list of two-element lists. Each inner list contains one unique pair [a, b] where a + b == x and a <= b.

Constraints

  • 0 <= len(nums) <= 10^5
  • -10^9 <= nums[i], x <= 10^9
  • The output must contain no duplicate pairs
  • Return pairs in lexicographic order

Function Signature

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