Find two numbers that sum to target
AmazonApplied Scientist · Technical ScreenLast 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
Solution walkthrough is for members
Get the full walkthrough with reference code and complexity analysis, plus Kitty Coach at 300 messages a day. Hints, the code runner and community answers stay free.