Indices for Two Sum
ARRAY
HASH TABLE
BINARY SEARCH

Problem

Given an array of integers numbers and a target integer target, return the indices of the two numbers such that they add up to target.

Assume that each input has exactly one solution, and you may not use the same element twice.

Examples:

findTwoSumIndices([1, 5, 9, 15], 14) // [2, 3] // numbers[2] + numbers[3] = 5 + 9 = 14 // so the indices are [2,3]. findTwoSumIndices([0, 5, 8, 12], 12) // [0, 3] findTwoSumIndices([-10, -3, 2, 0, 4], -1) // [1, 2]

Time Complexity

A target time complexity of less than O(n2) is desired for this problem.

Loading...