interviewmind

Practice room

Call time 00:00Get the app
D
Dana · Interviewer
You
You
Captions

Press Play and Dana asks the question out loud.

Questions5/17

CodingEasy

Two Sum

You’re given an array of integers nums and an integer target. Return the indices of the two numbers in nums that add up to target.

Every input has exactly one answer, and the same element can’t be used twice. Return the two indices in either order.

Example 1

Inputnums = [2,7,11,15], target = 9Output[0,1]

nums[0] + nums[1] = 2 + 7 = 9.

Example 2

Inputnums = [3,2,4], target = 6Output[1,2]

The 3 can’t pair with itself, so the answer is 2 + 4.

Example 3

Inputnums = [3,3], target = 6Output[0,1]

Constraints

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

Tab indents. Press Escape, then Tab, to move focus out of the editor.

TypeScriptLn 1, Col 1
Practice room — InterviewMind