Dataford
Interview QuestionsInterview GuidesExperiencesMock InterviewsPricing
Get started

Two Sum Pair Exists

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

Your question is Two Sum Pair Exists. 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 feature in the eToro watchlist service needs to detect whether two observed integer values combine to a specified target. Given an unsorted array of integers nums and an integer target, return True if two different elements sum to target; otherwise, return False.

Each array element may be used at most once. Duplicate values are allowed, so two separate occurrences of the same value can form a valid pair.

Formal Specification

  • Input: nums, a list of integers, and target, an integer.
  • Output: A boolean indicating whether indices i and j exist such that i != j and nums[i] + nums[j] == target.
  • The input array must not be modified.

Constraints

  • 0 <= nums.length <= 100,000
  • -10^9 <= nums[i], target <= 10^9
  • Duplicate values and negative values are allowed
  • The input array must not be modified

Function Signature

def has_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