# Given an array, find the two sum.

Aced (formerly Exponent) publishes a public search API over its indexed pages; the guide is at https://www.aced.io/agents/agent-access.

Source: https://www.aced.io/questions/1164/find-two-sum
Source observed: 2026-11-04T22:21:39.199Z
Last checked: 2026-11-04T22:21:39.199+00:00
Indexed: 2026-11-05T03:50:35.467+00:00

---

# Given an array, find the two sum.

**Difficulty:** Easy  
**Category:** Data Structures & Algorithms; Coding

## Problem

Given an integer array `nums` and an integer `target`, write a function `twoSum` that returns the indices of the two numbers whose sum equals `target`.

Assumptions and requirements:

- Each input has exactly one solution.
- You may not use the same element twice.
- If no pair exists, return an empty array.
- If multiple index pairs sum to the target, return the pair whose numbers appear first in the array.

## Examples

```text
Input: nums = [2, 7, 11, 15], target = 9
Output: [0, 1]

Input: nums = [3, 2, 4], target = 6
Output: [1, 2]
```

No community answers have been contributed. The page provides locked Solution access, community discussion, hints, a challenge, an editor, output and test-results panels, and [sign-up to run code](https://www.aced.io/signup?src=lesson).

## Interview metadata

The question is associated with 22 interviews and was last reported asked 2 months ago. Listed roles include Software Engineer (11), Data Engineer (5), Data Scientist (2), Machine Learning Engineer, and Mobile Engineer. Listed companies include Amazon (4), JP Morgan Chase (2), Goldman Sachs (2), Meta (2), Apple, Samsung, Oracle, PayPal, Visa, Intuit, Walmart Labs, IBM, Adobe, Intel, Salesforce, and DocuSign.

## Interview experiences

Five shared experiences are shown:

- **JP Morgan Chase · 2 months ago — Software Engineer · Intern:** The online assessment was relatively easy, the phone screen was similar, and it included many behavioral questions. [Read the experience](https://www.aced.io/experiences/jp-morgan-chase-software-engineer-intern-interview-79c97e).
- **Amazon · 2 years ago — Data Engineer · Intern:** The interviewers were friendly; the technical portion required thorough explanation of the thought process. [Read the experience](https://www.aced.io/experiences/amazon-data-engineer-intern-interview-d0041d).
- **DocuSign · 2 years ago — Software Engineer · Intern:** The process included an online assessment with a LeetCode medium dynamic-programming problem, recruiter and hiring-manager calls, and two coding interviews with LeetCode easy problems. [Read the experience](https://www.aced.io/experiences/docusign-software-engineer-intern-interview-3ff918).
- **Meta · 3 years ago — Software Engineer · Entry Level / L3:** The contributor described a rigorous process emphasizing bug-free code and behavioral fit. [Read the experience](https://www.aced.io/experiences/meta-facebook-software-engineer-interview-cfe4f7).
- **Amazon · 3 years ago — Software Engineer · Senior / L5:** The coding round focused on data structures and problem-solving. The contributor produced a baseline solution and explained the approach but struggled with optimization, edge cases, and optimal complexity under time pressure. [Read the experience](https://www.aced.io/experiences/amazon-senior-software-engineer-interview-8b8fb1).

## Related questions

- [Find a triplet in an array with a given sum.](https://www.aced.io/questions/1127/find-triplet-with-given-sum)
- [Find the maximum length sub-array with a given sum.](https://www.aced.io/questions/1115/find-maximum-length-sub-array-with-given-sum)
- [Find the maximum product subarray in a given array.](https://www.aced.io/questions/1126/maximum-product-subarray)

## Related courses

![Machine Learning Engineer Interview Prep](https://images.ctfassets.net/x78yjrjc11pq/6UfkHxUyLQVfDHSfLNQtWa/1be1539a65b4f6f15201f5b573c0a578/ML_Engineer_Interview_Prep_Course.jpeg?w=800&h=800&fm=webp&q=75)

### [Machine Learning Engineer Interview Prep](https://www.aced.io/courses/ml-engineer)

We cover mock interviews, frameworks, senior-candidate advice, ML system design, core concepts, coding, behavioral interviews, and more for roles at Meta, Google, Amazon, Apple, Microsoft, Nvidia, and other companies.

![Data Science Interview Prep](https://images.ctfassets.net/x78yjrjc11pq/3U4C5C0OkDR0UeGch4AmlE/7ad489430b676a088cb973307fe77884/Data_Science_Interview_Prep_Course.jpeg?w=800&h=800&fm=webp&q=75)

### [Data Science Interview Prep](https://www.aced.io/courses/data-science)

We cover mock interviews, frameworks, senior-candidate advice, statistics, experimentation, coding, SQL, machine learning, behavioral interviews, and more for roles at Google, Amazon, Microsoft, Meta, Apple, and other companies.

---

[Read this page’s summary](https://www.aced.io/agents/api/public/v1/page-tldr?url=https%3A%2F%2Fwww.aced.io%2Fquestions%2F1164%2Ffind-two-sum&trace=t_679ff9ab98f3)

## Ask a follow-up about this page

Need a more specific answer? Ask the exact question you have. It returns a fresh, cited answer from Aced (formerly Exponent)’s knowledge base. No account or API key required.

Open this URL with your own question, URL-encoded. Include your question in q. All research inputs are optional; no account or setup.

`GET https://www.aced.io/agents/agent/faq?q={question}&trace=t_679ff9ab98f3`

[Tool guide and examples](https://www.aced.io/agents/agent-access) · [OpenAPI](https://www.aced.io/agents/api/public/v1/openapi.json) · [Page TLDR form](https://www.aced.io/agents/agent-tools/page-tldr?url=https%3A%2F%2Fwww.aced.io%2Fquestions%2F1164%2Ffind-two-sum). Opening a form does not execute a tool.