Two Sum (Array)

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

Input Format

nums = array of integers, target = integer

Output Format

Indices of two numbers (0-based) whose sum equals target

Constraints

  • 2 <= nums.length <= 10^5

Examples

Example 1:

Input:

nums = [2,7,11,15]
target = 9

Output:

[0,1]

Explanation:

nums[0] + nums[1] = 9.

Loading...
Two Sum (Array) - Arrays DSA Problem