1. Two Sum
easyAsked at AMDGiven an array of integers and a target, return the indices of two numbers that add up to the target. AMD interviewers use this as a warm-up that checks whether you default to the O(n^2) brute force or immediately reach for a hash map to get O(n).
By Alex Chen, Founder, InterviewChamp.AI · Last verified
Source citations
Public interview reports confirming this problem appears in AMD loops.
- Glassdoor (2026-Q1)— AMD SWE phone screen reports consistently mention Two Sum as the first warm-up problem.
- Blind (2025-11)— Multiple AMD interview threads cite Two Sum as the classic O(n) hash-map opener for junior and new-grad rounds.
Problem
Given an array of integers nums and an integer target, return indices of the two numbers such that they add up to target. You may assume that each input would have exactly one solution, and you may not use the same element twice. You can return the answer in any order.
Constraints
2 <= nums.length <= 10^4−10^9 <= nums[i] <= 10^9−10^9 <= target <= 10^9Only one valid answer exists.
Examples
Example 1
nums = [2,7,11,15], target = 9[0,1]Explanation: nums[0] + nums[1] = 2 + 7 = 9.
Example 2
nums = [3,2,4], target = 6[1,2]Explanation: nums[1] + nums[2] = 2 + 4 = 6.
Approaches
1. Brute Force
Try every pair with two nested loops.
- Time
- O(n^2)
- Space
- O(1)
function twoSum(nums, target) {
for (let i = 0; i < nums.length; i++) {
for (let j = i + 1; j < nums.length; j++) {
if (nums[i] + nums[j] === target) return [i, j];
}
}
return [];
}Tradeoff: Simple but O(n^2). Acceptable only to establish a baseline before optimizing. AMD interviewers will ask for a faster approach immediately.
2. Hash Map (one pass)
Store each number's index in a map. For each element, check if its complement (target - nums[i]) is already in the map.
- Time
- O(n)
- Space
- O(n)
function twoSum(nums, target) {
const map = new Map();
for (let i = 0; i < nums.length; i++) {
const complement = target - nums[i];
if (map.has(complement)) return [map.get(complement), i];
map.set(nums[i], i);
}
return [];
}Tradeoff: O(n) time and O(n) space. This is the expected answer. The single-pass approach avoids scanning the map separately from populating it.
AMD-specific tips
AMD interviewers value precision about complexity. When you say O(n), also state the space trade-off — you're paying O(n) memory to save O(n) time. AMD engineers think about memory hierarchy: mention that the hash map trades memory bandwidth for compute cycles, which is a natural fit for the kind of reasoning they do around cache design. If asked about hardware analogy, a TLB is essentially a hardware two-sum lookup.
Common mistakes
- Using the same index twice — the problem forbids reusing the same element.
- Checking the map before inserting the current element would allow self-pairing on even-target duplicates; insert after checking.
- Returning values instead of indices — the problem asks for index positions.
- Assuming sorted input — the array is not necessarily sorted.
Follow-up questions
An interviewer at AMD may pivot to one of these next:
- Three Sum (LC 15) — extend to three elements summing to zero.
- What if the array is sorted? (Two-pointer O(1) space solution.)
- How would you handle this problem on a GPU with millions of elements?
Solve it now
Free. No sign-up. Python and JavaScript run instantly in your browser.
FAQ
Why not sort + two pointers?
Sorting destroys original indices which the problem requires. You'd need an auxiliary index array, making it O(n log n) time and O(n) space anyway — worse than the hash-map approach.
Can there be duplicate numbers?
Yes. The hash map approach handles duplicates correctly because you check for the complement before inserting the current element.
What if no solution exists?
The problem guarantees exactly one solution, but in production code you'd return an empty array or throw, depending on the contract.
Practice these live with InterviewChamp.AI
Drill Two Sum and other AMD interview questions under real-loop conditions with instant feedback on your reasoning, complexity claims, and code.
Practice these live with InterviewChamp.AI →