Find two numbers that sum to a target
Problem: Array Sum Lookup
Given an integer array nums and an integer target, find two distinct indices i and j such that nums[i] + nums[j] == target. The indices i and j must not be equal (i != j).
Return the pair of indices (in any order). If no such pair exists, return an empty result.
Clarifications (Assumed)
- Negative numbers are possible in
numsand fortarget. - If multiple valid pairs exist, any one can be returned.
- Output format should be 0-based indices.
Constraints
1 <= nums.length <= 1e5-1e9 <= nums[i], target <= 1e9
AI interview prep
Core dilemma
Optimizing for time complexity to handle large input arrays while managing space complexity, specifically finding a complementary pair efficiently.
2 tradeoffs and 2 stress tests locked
Interview prep
Unlock the interviewer X-Ray rubric, tradeoff matrix, stress tests, clarifying questions, and key concepts.
Find two numbers that sum to a target
Problem: Array Sum Lookup
Given an integer array nums and an integer target, find two distinct indices i and j such that nums[i] + nums[j] == target. The indices i and j must not be equal (i != j).
Return the pair of indices (in any order). If no such pair exists, return an empty result.
Clarifications (Assumed)
- Negative numbers are possible in
numsand fortarget. - If multiple valid pairs exist, any one can be returned.
- Output format should be 0-based indices.
Constraints
1 <= nums.length <= 1e5-1e9 <= nums[i], target <= 1e9