Dataford
Interview QuestionsInterview GuidesExperiencesMock InterviewsPricing
Get started

Two Sum Pair Sum

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

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

While processing integer values associated with events in the Securonix platform, determine whether two distinct values produce a required target total. Given an unsorted array nums and an integer target, return the indices of two elements whose values sum to target.

Return the indices in ascending order. Each array position may be used at most once. The input is guaranteed to contain exactly one valid pair.

Formal Specification

  • Input: nums, a list of integers, and target, an integer.
  • Output: A list [i, j] containing two distinct zero-based indices where i < j and nums[i] + nums[j] == target.
  • If no pair exists, return an empty list, although valid test inputs contain one pair.

Constraints

  • 2 <= len(nums) <= 100,000
  • -10^9 <= nums[i], target <= 10^9
  • nums is not necessarily sorted
  • Exactly one valid pair exists for each graded input

Function Signature

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