1. Two Sum
easyAsked at DatadogGiven an array of integers and a target, return indices of the two numbers that add up to the target. Datadog asks this as a warmup but pushes candidates to discuss how the same hashmap pattern scales to streaming pair-detection over high-cardinality metric IDs.
By Alex Chen, Founder, InterviewChamp.AI · Last verified
Source citations
Public interview reports confirming this problem appears in Datadog loops.
- Glassdoor (2026-Q1)— Datadog phone screens consistently open with hashmap warmups before moving to streaming variants.
- Blind (2025-11)— Reported as the lead-in question for Datadog backend infra screens.
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.
Constraints
2 <= nums.length <= 10^4-10^9 <= nums[i] <= 10^9Only one valid answer exists.
Examples
Example 1
nums = [2,7,11,15], target = 9[0,1]Explanation: nums[0] + nums[1] == 9.
Example 2
nums = [3,2,4], target = 6[1,2]Approaches
1. Brute force nested loop
Check every pair (i, j) for nums[i] + nums[j] == 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];
}
}
}Tradeoff: Quadratic — won't survive Datadog scale (10^4 series IDs at minimum).
2. Hashmap single pass (optimal)
Map each value to its index. For each element x, look for target - x in the map before inserting x.
- 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);
}
}Tradeoff: Single pass, O(n) time. Same pattern extends to streaming where you keep a bounded hashmap of recently-seen metric values.
Datadog-specific tips
Datadog cares less about the answer than about your articulation of memory tradeoffs at scale. After solving, expect to be asked: 'If this were a stream of 1B metric values per minute, how would you bound the map?' Mention sliding-window expiration or count-min-sketch as approximations.
Common mistakes
- Inserting nums[i] into the map BEFORE checking — breaks when target = 2*nums[i] and there's only one such element.
- Returning values instead of indices.
- Forgetting that the array can contain negatives — affects only your mental model, not the code, but interviewers will probe.
Follow-up questions
An interviewer at Datadog may pivot to one of these next:
- Two Sum II — sorted input, must use O(1) extra space (two pointers).
- Three Sum — extend the pattern with one outer loop + two pointers.
- Streaming Two Sum — values arrive one-at-a-time, must answer queries in O(1).
Solve it now
Free. No sign-up. Python and JavaScript run instantly in your browser.
FAQ
Why check before inserting?
If you insert first, an element could match itself when the target is 2*x. Checking first guarantees the indices are distinct.
What if multiple pairs satisfy the target?
The problem guarantees exactly one solution. In streaming Datadog variants you'd return all pairs and the answer becomes O(k) where k is the pair count.
Practice these live with InterviewChamp.AI
Drill Two Sum and other Datadog interview questions under real-loop conditions with instant feedback on your reasoning, complexity claims, and code.
Practice these live with InterviewChamp.AI →