1. Two Sum
easyAsked at Goldman SachsTwo Sum is Goldman Sachs's most common phone-screen warm-up: given an integer array and a target, return the indices of the two numbers that add up to the target. Goldman uses it to confirm you can articulate the space-for-time tradeoff before writing any code.
By Alex Chen, Founder, InterviewChamp.AI · Last verified
Source citations
Public interview reports confirming this problem appears in Goldman Sachs loops.
- Glassdoor (2026-Q1)— Goldman Sachs SWE phone-screen reports repeatedly list Two Sum as the first 10-15 minute warm-up.
- Blind (2025-12)— Multiple Goldman Sachs Strats and Engineering candidates report Two Sum on the initial HackerRank or virtual onsite round.
- LeetCode Discuss (2025-11)— Goldman Sachs company tag has Two Sum in the top-5 most-frequent problems.
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] == 9, so we return [0, 1].
Example 2
nums = [3,2,4], target = 6[1,2]Example 3
nums = [3,3], target = 6[0,1]Approaches
1. Brute-force nested loops
Try every (i, j) pair with i < j and return when nums[i] + nums[j] == target.
- Time
- O(n^2)
- Space
- O(1)
function twoSumBrute(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: Simplest to reason about and zero extra space. Acceptable to name as your starting point so Goldman sees you can articulate the cost; never leave it as your final answer.
2. Hash map (optimal, one-pass)
Store each value's index in a hash map as you scan. For each new num, look up target - num.
- Time
- O(n)
- Space
- O(n)
function twoSum(nums, target) {
const seen = new Map();
for (let i = 0; i < nums.length; i++) {
const need = target - nums[i];
if (seen.has(need)) return [seen.get(need), i];
seen.set(nums[i], i);
}
return [];
}Tradeoff: O(n) time at O(n) extra space — the canonical tradeoff Goldman interviewers want to hear named. One-pass works because by the time you'd pair X with Y, the earlier-occurring one is already in the map.
Goldman Sachs-specific tips
Goldman Sachs interviewers explicitly grade the brute-force → optimal narration on warm-ups like this one. Walk through the O(n^2) approach in words first, name the cost, then say 'I can trade space for time with a hash map' before coding. Goldman's HackerRank round is timed (typically 70-90 minutes for 2-3 problems), so practice typing the one-pass solution from muscle memory — getting Two Sum out in under 5 minutes leaves headroom for the harder follow-up.
Common mistakes
- Returning the values instead of the indices — the problem explicitly asks for indices.
- Writing the hash map as two passes (build, then lookup) when a single-pass is cleaner.
- Forgetting that duplicate values are allowed and must return distinct indices (nums = [3,3] target = 6 must return [0,1]).
Follow-up questions
An interviewer at Goldman Sachs may pivot to one of these next:
- What if the array were sorted? (Two-pointer in O(1) extra space.)
- What if you needed all pairs that sum to target? (Frequency map + careful duplicate handling.)
- Extend to Three Sum — find all unique triplets that sum to zero. (Sort + fix one + two-pointer the rest, O(n^2).)
Solve it now
Free. No sign-up. Python and JavaScript run instantly in your browser.
FAQ
Does Goldman Sachs still ask Two Sum in 2026?
Yes. Public Glassdoor reports through 2026-Q1 show Two Sum continues to appear in Goldman's first 10-15 minutes as a warm-up before a harder follow-up like Three Sum or a binary-search variant. It's effectively a smoke test for whether you can code at all.
Is the one-pass version actually expected, or is two-pass acceptable?
Both pass the rubric on correctness. The one-pass is preferred because it demonstrates you understand the invariant — when you arrive at index i, the map already contains every prior index, so any pair whose later half is i has its earlier half already stored. Naming that invariant is what gets you the 'strong communication' mark on Goldman's rubric.
Free learning resources
Curated free links for this problem.
Practice these live with InterviewChamp.AI
Drill Two Sum and other Goldman Sachs interview questions under real-loop conditions with instant feedback on your reasoning, complexity claims, and code.
Practice these live with InterviewChamp.AI →