Find two numbers that sum to a target
AgodaSoftware Engineer · Technical ScreenLast updated
This question evaluates array manipulation, index-based reasoning, and algorithmic problem-solving skills related to identifying value pairs that meet a numeric target.
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] == targeti != j
Return the pair of indices (in any order). If no such pair exists, return an empty result.
Clarifications to confirm in interview
- Are there negative numbers? (Assume yes.)
- If multiple answers exist, can we return any one? (Assume yes.)
- What output format is expected (0-based indices, 1-based indices, or the values themselves)? Specify and be consistent.
Constraints (typical)
1 <= nums.length <= 1e5-1e9 <= nums[i], 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.