Two Sum
Last updated
What is Two Sum?
You are given an array of integers and a target number. The goal is to find two numbers in the array that add up to the target and return their positions. The naive approach checks every pair, but the key insight is using a hash map to store numbers you have already seen, bringing the solution from O(n²) down to O(n). This problem teaches the core habit of trading space for time, a trade-off you will use constantly in harder problems.
Free resources to learn Two Sum
More in stage 4: Arrays & Hashing
Two Sum: common questions
Can I learn Two Sum in Hindi?
This lesson is written in English. Once you sign in, open it in the interactive course and ask the AI tutor to explain Two Sum in Hindi or Hinglish. The tutor answers from this lesson’s own text, so it stays on the syllabus, and it runs on your own Google, OpenAI or Anthropic key.
Is this Two Sum tutorial for beginners?
It is lesson 13 of 137 in the free LeetCode roadmap, in stage 4, Arrays & Hashing. If you are new to LeetCode, start from stage 1 and come back here in order; if you already know the earlier stages, this lesson stands on its own.