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.

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.

Hints

  1. Clarify edge cases before coding.
  2. Keep outputs deterministic when several valid answers exist.

Loading coding console...