Skip to main content

1. Two Sum

easyAsked at Atlassian

Two Sum is Atlassian's canonical phone-screen warm-up: given an integer array and a target, return the indices of the two numbers that add to the target. Atlassian uses it to confirm you can code and articulate the brute-to-optimal tradeoff before a harder graph or design follow-up.

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

Source citations

Public interview reports confirming this problem appears in Atlassian loops.

  • Glassdoor (2026-Q1)Atlassian SWE phone-screen reports list Two Sum as the opening 10-minute warm-up before a harder Jira/Confluence-themed follow-up.
  • Blind (2025-12)Atlassian L4 candidate threads cite Two Sum as a common opener for the technical phone 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^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]

Example 3

Input
nums = [3,3], target = 6
Output
[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. At n=10^4 the n^2 loop still runs in well under a second, but it's the wrong final answer for an Atlassian interviewer — they want you to name the optimal before they have to ask.

2. Hash map (optimal, one-pass)

Store each value's index as you scan; for each new num, look up target - num.

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 when you arrive at index i, the map already contains every prior index, so any pair whose later half is i has its earlier half already stored.

Atlassian-specific tips

Atlassian rewards clear narration. State the brute-force out loud first, name the cost in plain language, then say 'I can trade space for time with a hash map' and write the one-pass solution. Atlassian's coding rubric explicitly scores 'communicates tradeoffs', so jumping straight to the optimal without commentary actually loses points even though 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.
  • Forgetting duplicates are allowed — nums = [3,3] with target = 6 must return [0,1].

Follow-up questions

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

  • What if the array were sorted? Two-pointer in O(1) extra space.
  • What if you needed every pair that sums to target, not just one? Frequency map plus duplicate handling.
  • Three Sum — sort + fix one + two-pointer the rest, O(n^2).

Solve it now

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

Output

Press Run or Cmd+Enter to execute

FAQ

Does Atlassian still ask Two Sum in 2026?

Yes, but almost never as the final question. It is the 10-minute opener to confirm you can write working JavaScript or Python under a clock, then the interviewer pivots to a harder problem — often graph-based to mirror Jira's dependency model.

Is one-pass actually expected, or is two-pass acceptable at Atlassian?

Both pass on correctness, but one-pass is the canonical answer because it demonstrates the invariant: when you arrive at index i, the map contains every prior index, so any qualifying 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 Atlassian interview questions under real-loop conditions with instant feedback on your reasoning, complexity claims, and code.

Practice these live with InterviewChamp.AI →