Dashboard
LC #1

Two Sum

Pattern · ?AmazonGoogleMetaAppleMicrosoftBloombergAdobe

Problem

Given an array of integers nums and an integer target, return the indices [i, j] of the two numbers that add up to target. Exactly one solution always exists; you may not use the same element twice.

Constraints

  • 2 ≤ nums.length ≤ 10⁴
  • -10⁹ ≤ nums[i] ≤ 10⁹
  • Exactly one valid answer exists

Example

Input
nums = [2, 7, 11, 15], target = 9
Output
[0, 1]
Why
nums[0] + nums[1] = 2 + 7 = 9

Spot the pattern

Which pattern cracks it?

Hints

One at a time
Solve on LeetCode ↗