Problem, as an interviewer would state it:
"Implement twoSum(nums, target) — returning the INDICES of the two numbers in the array that add up to target, without using the same array element twice."
Examples:
twoSum([2,7,11,15], 9); // [0,1] -- nums[0]+nums[1] = 2+7 = 9
Clarifying questions expected:
- Does the answer need to return real ARRAY INDICES, or the actual matching VALUES themselves?
- If the SAME value could theoretically pair with itself to reach the target, can a single array element be used TWICE?
- Is exactly one valid answer guaranteed to exist, or does the function need to handle a genuinely "no valid pair" case?
Code / implementation expected: Yes — real, direct proof of correct index-pair detection, confirmation the same index is never used twice even with duplicate values present, and correct handling of a genuinely unsolvable case.