PracHub
QuestionsPremiumCoachesLearningGuidesInterview Prep

Quick Overview

This question evaluates a candidate's competency in basic algorithmic problem-solving within the Coding & Algorithms domain, focusing on array manipulation, pair-sum reasoning, and analysis of time-space trade-offs.

  • medium
  • Amazon
  • Coding & Algorithms
  • Machine Learning Engineer

Find two numbers that sum to target

Company: Amazon

Role: Machine Learning Engineer

Category: Coding & Algorithms

Difficulty: medium

Interview Round: Technical Screen

Given an integer array `nums` of length `n` and an integer `target`, return the indices `(i, j)` (0-based) of two **distinct** elements such that `nums[i] + nums[j] == target`. Requirements: - Return any one valid pair of indices. - You may assume **exactly one** valid pair exists. - The same element cannot be used twice. **Input:** `nums: int[]`, `target: int` **Output:** two indices `i, j` **Constraints (typical):** - `2 <= n <= 1e5` - `-1e9 <= nums[k] <= 1e9` - `-1e9 <= target <= 1e9`

Quick Answer: This question evaluates a candidate's competency in basic algorithmic problem-solving within the Coding & Algorithms domain, focusing on array manipulation, pair-sum reasoning, and analysis of time-space trade-offs.

Return a deterministic pair of distinct indices whose values sum to target.

Constraints

  • Inputs are Python literals matching the function signature.
  • Return a deterministic exact-match value.

Examples

Input: ([2,7,11,15], 9)

Expected Output: [0, 1]

Explanation: 2 + 7 matches the target.

Input: ([3,3], 6)

Expected Output: [0, 1]

Explanation: Distinct indices can hold equal values.

Input: ([0,4,3,0], 0)

Expected Output: [0, 3]

Explanation: The same value can be used from two different indices.

Hints

  1. Clarify edge cases before coding.
  2. Keep outputs deterministic when several valid answers exist.
Last updated: Jun 27, 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
  • 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)