PIXELBANKv8.2.1
Menu

Two Sum

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

Assume exactly one solution exists. Output two indices space-separated.

Example:

Input:
2,7,11,15
9
Output:
0 1
Reasoning:
  • The input array is [2,7,11,15][2, 7, 11, 15] and the target sum is 99.
  • We iterate through the array to find two numbers that add up to the target: 2+7=2 + 7 = 9$, which matches the target.
  • The indices of these two numbers in the array are 00 and 11, since array indices start at 00.
  • The final output is the space-separated indices: 010 1

Constraints:

  • 2 <= len(nums) <= 10^4
  • -10^9 <= nums[i] <= 10^9
  • Exactly one valid answer exists
Editor

Test Results

0/0
Run code to see test results.