Cascadiq

Two Sum

algorithm · Level 1 · 15 min

Description

Given an array of integers nums and an integer target, return 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.

You can return the answer in any order.

Requirements

  • Implement a function that takes nums (array of integers) and target (integer).
  • Return the two indices as an array [i, j] such that nums[i] + nums[j] === target.
  • Assume exactly one valid answer exists.

Constraints

- `2 <= nums.length <= 10^4` - `-10^9 <= nums[i] <= 10^9` - Only one valid answer exists.

Deliverables

Return the two indices. Order does not matter.

Tags

ArrayHash Table