As reported: Intuit SDE 2 (2025), onsite problem-solving round (60 min): find a pair whose sum equals a target, discussed from brute force through binary search to a hash map.
Given an integer array nums and an integer target, return the indices of the two numbers that add up to target. Exactly one solution exists, and the same element may not be used twice. The indices can be returned in any order.
This is LeetCode 1 — Two Sum.
Examples
nums = [2,7,11,15], target = 9 -> [0,1]
nums = [3,2,4], target = 6 -> [1,2]
nums = [3,3], target = 6 -> [0,1]
Constraints: 2 ≤ nums.length ≤ 10^4; -10^9 ≤ nums[i], target ≤ 10^9; exactly one valid answer.
Code runner format: one JSON value per line (LeetCode's test-case format): nums, then target. Implement twoSum(nums, target); the harness sorts the two indices before printing.