Dataford
Interview QuestionsInterview GuidesExperiencesMock InterviewsPricing
Get started

Target Sum Pair Finding

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

Your question is Target Sum Pair Finding. 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

Perforce Helix Core tooling may need to identify two numeric change metrics whose combined value matches a requested threshold. Given an array of integers and a target integer, return any pair of distinct elements whose values add up to the target. Return -1 if no such pair exists.

Formal Specification

Implement pair_sum(nums, target).

  • Input: nums, a list of integers, and target, an integer.
  • Output: A two-element list containing the values of two distinct array elements whose sum equals target, or the integer -1 when no pair exists.
  • An element may not be used twice, but duplicate values at different indices may form a valid pair.
  • If multiple pairs exist, return any one of them.

Constraints

  • 0 <= nums.length <= 100,000
  • -10^9 <= nums[i] <= 10^9
  • -10^9 <= target <= 10^9
  • Return any valid pair if multiple pairs exist
  • The same array element cannot be used twice

Function Signature

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