Coding Challenge

Two Sum

Easy
arrayhashmap

Return the indices of two numbers whose sum matches a target.

Given an integer array and a target, return the indices of the two distinct values whose sum equals the target. Assume exactly one valid pair exists.

Examples

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

Output: [0,1]

Constraints

  • 2 <= nums.length
  • Exactly one answer exists
  • Do not reuse the same element twice

Preparing your coding workspace...