1. Two Sum
easyAsked at ShopifyShopify uses Two Sum as the warm-up before pivoting into a follow-up about hash-map collisions or a real product scenario like 'find two SKUs whose price sums to a coupon target'. The interviewer is grading whether you narrate the O(n^2) -> O(n) tradeoff out loud.
By Alex Chen, Founder, InterviewChamp.AI · Last verified
Source citations
Public interview reports confirming this problem appears in Shopify loops.
- Glassdoor (2026-Q1)— Shopify Backend Developer Intern + Production Engineer phone screens list Two Sum as a 10-15 minute warm-up.
- Reddit r/cscareerquestions (2025-12)— Shopify new-grad reports cite Two Sum followed by a product-pricing variant in the same round.
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
Check every (i, j) pair with i < j until one sums to 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: Easy to write; constant extra space. At n = 10^4 this still finishes in well under a second, but you should never leave this on the whiteboard at Shopify without naming the optimal.
2. Hash map (one-pass, optimal)
Walk the array once, storing each value's index. For each num, check whether target - num is already in the map.
- 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 — Shopify's bar for the warm-up. One-pass works because by the time you see the second number of a valid pair, the first one is already in the map.
Shopify-specific tips
Shopify interviewers grade Two Sum on the narration, not the code. Before coding, say 'the brute force is O(n^2) — let me trade space for time with a hash map.' Then write the one-pass. Expect a product follow-up: 'now imagine these are line-item prices and the target is a coupon threshold — how would you return all pairs?' Be ready to pivot.
Common mistakes
- Returning the values instead of the indices.
- Building the hash map fully before scanning (two-pass) when a one-pass is cleaner and shorter.
- Forgetting that duplicate values are valid (nums = [3,3] with target 6 returns [0,1]).
- Not naming the brute-force first — Shopify interviewers want to hear the tradeoff out loud.
Follow-up questions
An interviewer at Shopify may pivot to one of these next:
- What if you needed every pair, not just one? (Frequency map; handle duplicates carefully.)
- What if the array is sorted? (Two-pointer in O(1) extra space.)
- Extend to Three Sum. (Sort + fix one + two-pointer the rest, O(n^2).)
- What if the input is a stream and you can only see each number once?
Solve it now
Free. No sign-up. Python and JavaScript run instantly in your browser.
FAQ
Does Shopify still ask Two Sum in 2026?
Yes, but almost always as a warm-up before a harder follow-up — Three Sum, the all-pairs variant, or a product-flavored version like 'find two cart items whose prices sum to a discount threshold'. Expect 10-15 minutes on Two Sum and then a pivot.
Should I write the brute-force first or skip straight to the hash map?
Name the brute-force out loud, then write the optimal. Shopify's rubric (per public reports) explicitly tests whether you can articulate the space-for-time tradeoff. Skipping the brute-force narration is a soft red flag.
Free learning resources
Curated free links for this problem.
Practice these live with InterviewChamp.AI
Drill Two Sum and other Shopify interview questions under real-loop conditions with instant feedback on your reasoning, complexity claims, and code.
Practice these live with InterviewChamp.AI →