Katkat

Find two numbers that sum to target

AmazonApplied Scientist · Technical Screen

Last updated

This question evaluates a candidate's competency in basic algorithmic problem-solving within the Coding & Algorithms domain, focusing on array manipulation, pair-sum reasoning, and analysis of time-space trade-offs.

Given an integer array nums of length n and an integer target, return the indices (i, j) (0-based) of two distinct elements such that nums[i] + nums[j] == target.

Requirements:

  • Return any one valid pair of indices.
  • You may assume exactly one valid pair exists.
  • The same element cannot be used twice.

Input: nums: int[], target: int

Output: two indices i, j

Constraints (typical):

  • 2 <= n <= 1e5
  • -1e9 <= nums[k] <= 1e9
  • -1e9 <= target <= 1e9