Two Sum

Try to solve the Two Sum problem.

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 ≤104\leq 10^4
  • −109≤-10^9 \leq arr[i] ≤109\leq 10^9
  • −109≤-10^9 \leq t ≤109\leq 10^9
  • Only one valid answer exists.

Examples

Level up your interview prep. Join Educative to access 80+ hands-on prep courses.