1. Two Sum
easyAsked at UberTwo Sum is Uber's go-to phone-screen warm-up: given an integer array and a target, return the indices of the two numbers that sum to it. Uber's bar is that you state the brute-force complexity before reaching for the hash map.
By Alex Chen, Founder, InterviewChamp.AI · Last verified
Source citations
Public interview reports confirming this problem appears in Uber loops.
- Glassdoor (2026-Q1)— Uber new-grad phone-screen reports list Two Sum as the standard opener.
- Levels.fyi (2026-Q1)— Uber L4 interview experiences mention Two Sum as a 10-15 minute warm-up.
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
For every pair (i, j) with i < j, check if 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: Zero extra space, but quadratic time. Useful to name first so the interviewer sees you can spot the inefficiency before jumping to the hash map.
2. Hash map (optimal, one-pass)
Store each value's index in a map. 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: Trades O(n) extra space for O(n) time. One-pass works because by the time you'd want to pair x with y, the earlier of the two is already in the map.
Uber-specific tips
Uber phone-screeners specifically reward the brute-force-then-optimal narration on this question. They want to hear 'I could try every pair in O(n^2) — let me do better with a hash map.' Coding the hash map silently without stating the tradeoff is a common red flag at Uber's bar.
Common mistakes
- Returning the values instead of the indices.
- Writing a two-pass hash map (build then lookup) when one-pass is cleaner.
- Forgetting duplicates are allowed (nums = [3,3] with target 6 returns [0,1]).
Follow-up questions
An interviewer at Uber may pivot to one of these next:
- What if the array were sorted? (Two-pointer in O(1) extra space.)
- What if we wanted all pairs that sum to target, not just one? (Frequency map + careful duplicate handling.)
- Three Sum extension (LC 15): 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 Uber really still ask Two Sum in 2026?
Yes — as a phone-screen warm-up to confirm you can code at all before the harder follow-up. Expect the interviewer to pivot to a harder array problem after 10-15 minutes.
Is the one-pass version actually expected over two-pass?
Both pass on correctness, but the one-pass is canonical because it shows you understand the invariant: when you arrive at index i, every earlier value is already in the map, so any pair with i as the later half has its earlier half stored.
Free learning resources
Curated free links for this problem.
Practice these live with InterviewChamp.AI
Drill Two Sum and other Uber interview questions under real-loop conditions with instant feedback on your reasoning, complexity claims, and code.
Practice these live with InterviewChamp.AI →