code.davidloor.com
EEasy· array· hash-map

Two Sum

Two Sum

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

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

Example

Input: nums = [2, 7, 11, 15], target = 9 Output: [0, 1] (because nums[0] + nums[1] == 9)

Constraints

  • 2 <= nums.length <= 10^4
  • -10^9 <= nums[i] <= 10^9
  • -10^9 <= target <= 10^9

Entry — twoSum

Grading — set over 3 tests

Stuck? Browse algorithmic patterns → or read the Python / JS foundations.
Awaiting first run
Reference solution unlocks after a run & 60 s of work.