1. Two Sum
easyAsked at CitadelCitadel uses Two Sum as a calibration problem in SWE phone screens — they want to see if you immediately reach for a hash map rather than nested loops. At Citadel's latency targets, the difference between O(n) and O(n²) at 10M ticks/sec is not academic.
By Alex Chen, Founder, InterviewChamp.AI · Last verified
Source citations
Public interview reports confirming this problem appears in Citadel loops.
- Glassdoor (2026-Q1)— Citadel SWE phone screen reports consistently mention Two Sum as an opening warm-up question.
- Blind (2025-10)— Multiple Citadel SWE threads confirm Two Sum appears in early-round screens, graded on O(n) approach, not just correctness.
Problem
Given an array of integers nums and an integer target, return the indices of the two numbers that add up to target. You may assume each input has exactly one solution, and you may not use the same element twice. Return the answer in any order.
Constraints
2 <= nums.length <= 10^4−10^9 <= nums[i] <= 10^9−10^9 <= target <= 10^9Exactly 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 (O(n²))
Try every pair. Acceptable to mention as the naive baseline but never code this as your final answer at Citadel.
- Time
- O(n²)
- 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 to reason about but O(n²) — unacceptable at Citadel's data volumes. Present it briefly, then immediately pivot to the hash-map approach.
2. Hash map (one pass)
For each element, check whether its complement (target − nums[i]) already exists in the map. If yes, return. Otherwise, store the current element and its index.
- Time
- O(n)
- Space
- O(n)
function twoSum(nums, target) {
const seen = new Map(); // value -> index
for (let i = 0; i < nums.length; i++) {
const complement = target - nums[i];
if (seen.has(complement)) {
return [seen.get(complement), i];
}
seen.set(nums[i], i);
}
return [];
}Tradeoff: Single pass, O(n) time, O(n) space. Hash map lookup is O(1) average. This is the expected answer — state the hash map approach before writing a single line.
Citadel-specific tips
Citadel interviewers explicitly ask about latency implications. After coding the O(n) solution, expect: 'At 10 million price-update events per second, what is the worst-case latency of the O(n²) approach versus O(n)?' Be ready to say: at 10M events, O(n²) could be 10^14 operations per batch — completely infeasible. The hash map approach is what you'd see in a real tick-data ingestion pipeline. Also mention that in practice you'd pre-sort a price array and use the two-pointer approach if indices don't matter, because sorted order is a natural property of order books.
Common mistakes
- Jumping straight into the nested-loop approach without acknowledging the O(n) alternative — Citadel interviewers mark you down immediately.
- Forgetting that the same index cannot be used twice (i ≠ j) — verify your solution handles nums = [3, 3], target = 6 correctly.
- Using an array instead of a Map for the complement lookup — O(n) lookup destroys the asymptotic advantage.
- Not handling negative numbers or zero — the complement calculation works for all integers, but explicitly confirm this to the interviewer.
Follow-up questions
An interviewer at Citadel may pivot to one of these next:
- Two Sum II (LC 167) — array is sorted; solve in O(1) space with two pointers.
- Three Sum (LC 15) — reduce to Two Sum; Citadel often follows up with this in the same session.
- What if there can be multiple valid pairs and you need to return all of them?
Solve it now
Free. No sign-up. Python and JavaScript run instantly in your browser.
FAQ
Why does Citadel ask an 'easy' problem like Two Sum?
It's a filter for the O(n) instinct. If you open with a nested loop without mentioning the hash map, the interview effectively ends. They want to see you reason about time complexity immediately.
Two-pointer vs hash map — which does Citadel prefer?
Hash map, because the array is unsorted. If the follow-up specifies a sorted array, pivot to two-pointer for O(1) space.
Should I sort first?
Sorting is O(n log n) and loses original indices. Only sort if you don't need to return indices — which is not the case here.
Practice these live with InterviewChamp.AI
Drill Two Sum and other Citadel interview questions under real-loop conditions with instant feedback on your reasoning, complexity claims, and code.
Practice these live with InterviewChamp.AI →