Dataford
Interview QuestionsInterview GuidesExperiencesMock InterviewsPricing
Get started

Pairs With Sum K

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

Your question is Pairs With Sum K. 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

Luxoft Singapore services may process numeric event attributes where analysts need to identify combinations that reach a specified threshold. Given an integer array and target k, return every unique pair of values whose sum equals k.

Each array element can be used at most once for a pair. If duplicate values produce the same value pair, include that pair only once. Return the result as a list of two-element lists sorted lexicographically, first by the smaller value and then by the larger value. Return an empty list when no pair exists.

Formal Specification

Implement find_pairs(nums, k).

  • Input: nums, a list of integers, and k, an integer target sum.
  • Output: a list of unique two-element integer lists [a, b], where a <= b and a + b == k.
  • A pair may use two equal values only when those values occur at least twice in nums.

Constraints

  • 1 <= len(nums) <= 10^5
  • -10^9 <= nums[i] <= 10^9
  • -10^9 <= k <= 10^9
  • Each output pair contains distinct array occurrences
  • Duplicate value pairs must be returned only once

Function Signature

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