PracHub
QuestionsCoachesLearningGuidesInterview Prep

Quick Overview

This question evaluates skills in array processing, pair-sum detection, handling duplicate values and multiset counts, and reasoning about algorithmic complexity and correctness.

  • Medium
  • Amazon
  • Coding & Algorithms
  • Data Scientist

Identify Number Pairs Adding to Target in Array

Company: Amazon

Role: Data Scientist

Category: Coding & Algorithms

Difficulty: Medium

Interview Round: Technical Screen

##### Scenario Coding round to identify all number pairs that add up to a target in an array containing duplicates. ##### Question Given an integer array (may contain duplicates) and a target sum, return all pairs of values whose sum equals the target, e.g. [1,2,1,0], target=3 -> [(1, 2)]. ##### Hints Use hashmap or sort+two-pointer; account for duplicate counts.

Quick Answer: This question evaluates skills in array processing, pair-sum detection, handling duplicate values and multiset counts, and reasoning about algorithmic complexity and correctness.

Given an integer array nums (may contain duplicates) and an integer target, return all unique value pairs [a, b] such that a + b == target. Each pair must appear once regardless of how many times the values occur. Include [x, x] only if nums contains at least two occurrences of x. Return pairs sorted: within each pair a <= b, and the list sorted lexicographically by (a, b). Indices do not matter.

Constraints

  • 0 <= n <= 200000
  • -10^9 <= nums[i], target <= 10^9
  • Return value-based pairs only; indices are irrelevant
  • Include [x, x] only if count(x) >= 2
  • Within each pair a <= b; output list sorted lexicographically by (a, b)

Hints

  1. Count frequencies with a hashmap; iterate unique values x and check if target - x exists.
  2. To avoid duplicates, only form pairs where x <= target - x.
  3. If x == target - x, include [x, x] only when frequency[x] >= 2. Alternatively, sort the array and use two pointers while skipping duplicates.
Last updated: Mar 29, 2026

Loading coding console...

PracHub

Master your tech interviews with 8,000+ real questions from top companies.

Product

  • Questions
  • Learning Tracks
  • Interview Guides
  • Resources
  • Premium
  • For Universities
  • Student Access

Browse

  • By Company
  • By Role
  • By Category
  • Topic Hubs
  • SQL Questions
  • AI Coding Questions
  • Compare Platforms
  • Discord Community

Support

  • support@prachub.com
  • (916) 541-4762

Legal

  • Privacy Policy
  • Terms of Service
  • About Us

© 2026 PracHub. All rights reserved.

Related Coding Questions

  • Implement Top-p (Nucleus) Sampling in NumPy - Amazon (medium)
  • Implement Multi-Head Attention from Scratch in NumPy - Amazon (medium)
  • Detect and Break a Cycle in a Singly Linked List - Amazon (medium)
  • Caesar Cipher with Translation-Table Optimization - Amazon (medium)
  • Minimum Drone Delivery Time on a Ring of Hubs - Amazon (medium)