1. Two Sum
easyAsked at IntuitGiven an array of integers and a target, return indices of two numbers that add up to the target. Intuit asks this as a screen to test whether you spot the hash-map optimization and whether you handle financial-precision concerns when the values represent cents.
By Alex Chen, Founder, InterviewChamp.AI · Last verified
Source citations
Public interview reports confirming this problem appears in Intuit loops.
- Glassdoor (2026-Q1)— Intuit phone-screen warm-up, often framed in terms of matching invoice amounts.
- LeetCode Discuss (2025-11)— TurboTax SWE phone screen cited Two Sum as the opening problem.
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]Approaches
1. Brute force double loop
Try every pair (i, j) with j > i and check if their sum equals target.
- 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: Quadratic and obvious — mention but immediately propose the hash-map version.
2. Single-pass hash map (optimal)
Walk the array once. For each value, check whether target - value has been seen before; if yes, return the indices. Otherwise store the current value's index.
- 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: Linear time, single pass. Trade O(n) space for O(n^2) → O(n) time.
Intuit-specific tips
Intuit interviewers asking financial-flavored variants will probe whether you'd use floats here — say no, use integer cents to avoid precision drift. Also articulate edge cases like duplicates (e.g., nums = [3,3], target = 6) and whether the function should mutate input. Bonus signal: mention that the hash-map approach handles negative numbers identically (no extra branching needed).
Common mistakes
- Using the same index twice (e.g., nums = [3,2,4], target = 6 returning [0,0]).
- Storing in the map before checking, so a value pairs with itself.
- Using floats if the prompt implies money — interviewers note the precision risk.
Follow-up questions
An interviewer at Intuit may pivot to one of these next:
- Two Sum II — sorted input, return 1-indexed values not indices (LC 167).
- Return ALL pairs that sum to target (deduped).
- Three Sum — extend the approach to triples (LC 15).
Solve it now
Free. No sign-up. Python and JavaScript run instantly in your browser.
FAQ
What if there are duplicates in the array?
The hash-map version handles them correctly because we check before inserting. For nums = [3,3], target = 6 the first 3 is stored, the second 3 finds it, returns [0,1].
How would this change for cents-as-integers vs dollars-as-floats?
Use integer cents. Floats accumulate IEEE-754 rounding errors — at Intuit scale (millions of transactions) this matters. The algorithm is identical; the data type matters.
Practice these live with InterviewChamp.AI
Drill Two Sum and other Intuit interview questions under real-loop conditions with instant feedback on your reasoning, complexity claims, and code.
Practice these live with InterviewChamp.AI →