1. Two Sum
easyAsked at TwilioTwo Sum is Twilio's canonical phone-screen warm-up: given an integer array and a target, return the indices of the two numbers that add up to the target. Twilio's bar is that you name the brute-force, the hash-map tradeoff, and walk through duplicate-value edge cases before coding.
By Alex Chen, Founder, InterviewChamp.AI · Last verified
Source citations
Public interview reports confirming this problem appears in Twilio loops.
- Glassdoor (2026-Q1)— Recurring across Twilio SWE phone-screen reports as the 10-minute warm-up before a harder follow-up.
- LeetCode Discuss (2025-11)— Multiple Twilio interview reports list Two Sum as the opener in the initial recruiter-coordinated technical screen.
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. Twilio reviewers want you to name this first so they know you understand the baseline before optimizing — skipping it is a yellow flag on the rubric.
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 before insertion.
- 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. One-pass works because by the time you'd want to pair X with Y, you've already inserted whichever appeared first.
Twilio-specific tips
Twilio interviewers grade narration as heavily as code. State the brute-force complexity out loud, then say 'I can trade space for time with a hash map' before writing the optimal. Twilio's rubric explicitly tests whether candidates can articulate the space-for-time tradeoff in plain language — silent jumps to the optimal lose points even when the code is correct.
Common mistakes
- Returning the values instead of the indices.
- Writing the hash map as two passes (build then lookup) when a one-pass is cleaner and demonstrates the loop invariant.
- Forgetting that duplicate values are allowed — nums = [3,3] with target 6 must return [0,1].
Follow-up questions
An interviewer at Twilio may pivot to one of these next:
- What if the array were sorted? (Two-pointer in O(1) extra space.)
- What if we needed all unique pairs that sum to target? (Frequency map plus duplicate handling.)
- What if this powered a /messages search-by-cost endpoint at Twilio scale — how would you handle a streamed input you cannot fully materialize?
Solve it now
Free. No sign-up. Python and JavaScript run instantly in your browser.
FAQ
Does Twilio still ask Two Sum in 2026?
Yes, but almost always as a 10-minute warm-up at the start of the recruiter-coordinated technical screen. Public Twilio reports on Glassdoor and LeetCode Discuss show it pairs with a harder follow-up (Group Anagrams or a rate-limiter design) in the same session.
Is the one-pass hash map version actually expected, or is two-pass acceptable?
Both pass the rubric on correctness, but the one-pass is the canonical answer because it demonstrates you understand the invariant: when you arrive at index i, the map contains every prior index, so any pair whose later half is i has its earlier half already stored.
Free learning resources
Curated free links for this problem.
Practice these live with InterviewChamp.AI
Drill Two Sum and other Twilio interview questions under real-loop conditions with instant feedback on your reasoning, complexity claims, and code.
Practice these live with InterviewChamp.AI →