Skip to main content

1. Two Sum

easyAsked at Adobe

Given an array of integers and a target, return indices of the two numbers that add up to the target. Adobe phone screens use this as the warm-up that decides whether you understand the array-to-hashmap conversion that powers nearly every duplicate/lookup task in image-processing pipelines.

By Alex Chen, Founder, InterviewChamp.AI · Last verified

Source citations

Public interview reports confirming this problem appears in Adobe loops.

  • Glassdoor (2026-Q1)Adobe SDE-I phone screen reports cite this as the first warm-up question.
  • LeetCode Discuss (2025-11)Adobe MTS interviewers frequently open with this before harder array problems.

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. Return the answer in any order.

Constraints

  • 2 <= nums.length <= 10^4
  • -10^9 <= nums[i] <= 10^9
  • -10^9 <= target <= 10^9
  • Only one valid answer exists.

Examples

Example 1

Input
nums = [2,7,11,15], target = 9
Output
[0,1]

Explanation: nums[0] + nums[1] == 9, so we return [0, 1].

Example 2

Input
nums = [3,2,4], target = 6
Output
[1,2]

Approaches

1. Brute force nested loops

Check every pair (i, j) where i < j.

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 — fine for tiny arrays but Adobe expects you to recognize the hashmap optimization immediately.

2. Hashmap one-pass

Iterate once; for each num, check if (target - num) is already in the map. If so, return its index. Otherwise, store num -> index.

Time
O(n)
Space
O(n)
function twoSum(nums, target) {
  const seen = new Map();
  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);
  }
}

Tradeoff: Linear time and space. The key insight: instead of looking 'forward' for each pair, ask 'have I already seen the complement?' That single mental flip is what Adobe phone screens grade.

Adobe-specific tips

Adobe screens this for clean variable naming (use 'complement' not 'x') and tight code. They'll often follow up with 'what if the array fits in memory but the target is a float — say a color delta — what changes?' Be ready to discuss floating-point equality and tolerance-based matching used in color-pipeline lookups.

Common mistakes

  • Using the same index twice — forgetting that nums[i] + nums[i] is not allowed.
  • Storing all values first, then iterating — wastes the one-pass elegance.
  • Returning the values instead of the indices — read the problem statement carefully.

Follow-up questions

An interviewer at Adobe may pivot to one of these next:

  • What if the array is sorted? (Two-pointer approach, O(1) space.)
  • What if there are multiple valid pairs and you need all of them?
  • Three Sum (LC 15) — natural follow-up extending this pattern.

Solve it now

Free. No sign-up. Python and JavaScript run instantly in your browser.

Output

Press Run or Cmd+Enter to execute

FAQ

Why a hashmap instead of sorting?

Sorting destroys the original indices, which the problem asks you to return. A hashmap preserves index information while giving O(1) lookup.

What if there are duplicates like [3, 3] target=6?

The one-pass approach handles it: when you process the second 3, the first 3 is already in the map with its index, so you return [0, 1].

Practice these live with InterviewChamp.AI

Drill Two Sum and other Adobe interview questions under real-loop conditions with instant feedback on your reasoning, complexity claims, and code.

Practice these live with InterviewChamp.AI →