Simple two-sum
Input
nums = [2,7,11,15], target = 9
Output
(0, 1)
nums[0] + nums[1] == 9, so return indices (0,1).
Full lesson preview
Find indices of two numbers that add up to a target using a hash map for O(n) time.
Problem statement
Task
Examples
Input
nums = [2,7,11,15], target = 9
Output
(0, 1)
nums[0] + nums[1] == 9, so return indices (0,1).
Input format
Output format
Constraints
Samples
Input
two_sum_hash([3,2,4], 6)
Output
(1, 2)
nums[1] + nums[2] == 6.