Dataford
Interview QuestionsInterview GuidesExperiencesMock InterviewsPricing
Get started
Two-Sum Existence for Target Sum
00:00
5 left

Two-Sum Existence for Target Sum

EasyPython

Problem

A Tower Research Capital market-data component receives an array of integer signals and a target value. Determine whether two distinct elements in the array have a sum exactly equal to the target.

Implement contains_pair_sum(nums, target) and return True if such a pair exists, otherwise return False. An element may not be used twice, but duplicate values at different indices may form a valid pair.

Formal Specification

  • Input: nums, a list of integers, and target, an integer.
  • Output: A boolean indicating whether there are indices i and j such that i != j and nums[i] + nums[j] == target.
  • The input list may be unsorted and may contain negative values or duplicates.

Constraints

  • 0 <= len(nums) <= 100,000
  • -10^9 <= nums[i] <= 10^9
  • -10^9 <= target <= 10^9
  • The two elements must come from distinct indices

Function Signature

def contains_pair_sum(nums, target):
Interviewer

Your question is Two-Sum Existence for Target Sum. Start with the requirements in the Question tab.

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.
CodePython 3
You need to log in / sign up to run or submit.Ln 2
Run your code to see test output here.