Easy•Array · Hash Map
LeetCode #1Two Sum
Given an array of numbers and a target, return the indexes of two different numbers whose sum equals the target.
In very simple words
Find two numbers that make the target, but return their positions. You cannot use the same position twice.
[2, 7, 11, 15], target = 92 + 7 = 9 → return [0, 1]
[3, 2, 4], target = 62 + 4 = 6 → return [1, 2]
Important: return indexes such as [0, 1], not the values [2, 7].
Have you solved it before?
The final answer stays hidden in both modes.
Solve It With Small Hints
Read one hint, pause, and try again before opening the next.
Step 1
Say the question in your own words
Find two different positions in the array whose values add up to the target. Return the positions, not the values.
For nums = [2, 7, 11, 15] and target = 9, return [0, 1] because nums[0] + nums[1] = 9.
Complete Answer
Both approaches, dry runs, Go code, complexity, and mistakes.
The solution is hidden. Use the guided hints first so you still solve the problem yourself.