FastPrepTwo Sum
Problems/Two Sum

Two Sum

Amazon logoAmazon● EasyFULLTIMENEW GRADINTERNOAPHONE SCREEN

Updated Nov 2026

QuestionFunctionExamplesConstraints

Problem statement

Source note: Reported in an Amazon phone screen for full-time, new grad, and intern roles. The report names Two Sum and a variation it does not describe. It gives no examples and no tie rule. Our version covers the shared base problem, with a fixed rule for what to return. We do not guess at the unnamed variation. Our version is about 80% the same as the reported question.

Given an integer array nums and an integer target, find two distinct indices whose values add to target.

Return a two-element array [i, j], where 0 <= i < j < nums.length and nums[i] + nums[j] = target. At least one valid pair exists. If several pairs are valid, return the lexicographically smallest pair: minimize i first, then j.

Function

twoSum(nums: int[], target: int) → int[]

Examples

Example 1

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

nums[0] + nums[1] = 2 + 7 = 9.

Example 2

nums = [3,2,4]target = 6return = [1,2]

nums[1] + nums[2] = 2 + 4 = 6.

Example 3

nums = [3,3]target = 6return = [0,1]

The two equal values occupy distinct indices and form the required pair.

Constraints

  • 2 <= nums.length <= 100000.
  • -10^9 <= nums[i] <= 10^9.
  • -10^9 <= target <= 10^9.
  • At least one valid pair exists.

More Amazon Phone Screen questions

  • Course SchedulePHONE SCREEN · ONSITE INTERVIEW · Seen Nov 2026
  • Search in a Rotated Sorted ArrayPHONE SCREEN · ONSITE INTERVIEW · Seen Nov 2026
  • Top K Frequent ElementsOA · PHONE SCREEN · ONSITE INTERVIEW · Seen Nov 2026
  • LRU Cache for Query ResultsPHONE SCREEN · ONSITE INTERVIEW · Seen Nov 2026
  • Course Schedule IIPHONE SCREEN · ONSITE INTERVIEW · Seen Nov 2026
  • Minimum Time to Spread Through a GridPHONE SCREEN · ONSITE INTERVIEW · Seen Nov 2026
  • Consistent-Hash Packet RouterPHONE SCREEN · Seen Nov 2026
  • Count Connected ComponentsPHONE SCREEN · Seen Nov 2026
  • Second Largest Distinct ElementPHONE SCREEN · Seen Nov 2026
  • Task SchedulerOA · PHONE SCREEN · ONSITE INTERVIEW · Seen Nov 2026

Similar questions at other companies

  • Macaron Order with Set DiscountsShopify · OAShopify interview questions
  • Merchant Payout Reserve CalculatorStripe · PHONE SCREENStripe interview questions
  • Build the Task HierarchyPendo · OA
  • Price CheckBlue Origin · PHONE SCREEN
  • Majority ElementByteDance · PHONE SCREENByteDance interview questions
  • Count User Mentions in Chat MessagesRamp · OARamp interview questions
  • Detect a Straight FlushTemu · PHONE SCREENTemu interview questions
  • Recommend Films from Viewers Who Watched Everything You DidBloomberg LP · PHONE SCREENBloomberg LP interview questions
  • Count Valid Square PairsAuxoAI · OA
  • Find Unique ElementsCisco · PHONE SCREENCisco interview questions

Interview reports that mention this question

  • Amazon Intern OA Problems: Every Task We Have (Part 2 of 5)
  • Amazon Frontend Spring 2025 Loops: 11 Experiences (Part 2 of 2)
  • Amazon Frontend Engineer Interviews: 21 Experiences (Part 1 of 2)
  • Amazon New Grad SDE Onsite Interview Questions: 17 Experiences

Amazon interview experiences

  • Amazon Experienced SDE Onsite Questions: 1 Experience
  • Amazon SDE Onsite Interview Questions: 9 Experiences
See Amazon hiring insights
Saved
class Solution {
    public int[] twoSum(int[] nums, int target) {
        // write your code here
    }
}
Checking account…