Search⌘ K
AI Features

Two Sum

Two Sum gives you an array of integers, including possible negative values, and a target. Return the two distinct zero-based indices whose values add to the target. A unique answer exists.

Statement

For the given array of integers arr and a target t, you have to identify the two indices that add up to generate the target t. Moreover, you can’t use the same index twice, and there will be only one solution.

Note: We will assume that the array is zero-indexed and the output order doesn’t matter.

Constraints:

  • 2≤2 \leq arr.length ≤103\leq 10^3
...