# Find a triplet in an array with a given sum — Aced

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/1127/find-triplet-with-given-sum
Source observed: 2026-11-05T00:06:02.048Z
Last checked: 2026-11-05T00:06:02.048+00:00
Indexed: 2026-11-06T19:43:18.181+00:00

---

# Find a triplet in an array with a given sum

**Difficulty:** Medium  
**Category:** Data Structures & Algorithms

We provide this coding interview question for practicing array and algorithm problems. It asks you to return every unique combination of three distinct array elements whose sum is zero.

## Problem

Given an integer array `nums`, return all unique triplets `[nums[i], nums[j], nums[k]]` such that:

- `i != j`, `i != k`, and `j != k`
- `nums[i] + nums[j] + nums[k] == 0`

The solution set must not contain duplicate triplets.

## Examples

```text
nums = [-1, 0, 1, 2, -1, -4]
output: [[-1, -1, 2], [-1, 0, 1]]
explanation: The triplets [-1, -1, 2] and [-1, 0, 1] are the only unique combinations that sum to zero.

nums = [1, 2, -2, -1]
output: []
explanation: There are no three numbers in the array that add up to zero.

nums = [-2, 0, 1, 1, -2, -1, 0, 2, -1]
output: [[-2, 0, 2], [-2, 1, 1], [-1, -1, 2], [-1, 0, 1]]
explanation: The array contains four unique triplets that sum to zero.
```

## Practice and access

Our question interface includes **Question**, **Solution**, **Mock Interview**, and **Community** tabs. The solution area is available through our upgrade flow: [Upgrade](https://www.aced.io/upgrade?src=questions). You can also [sign up to run code](https://www.aced.io/signup?src=lesson).

The question metadata includes:

- **Reported last asked:** 5 months ago
- **Roles:** [Software Engineer](https://www.aced.io/questions?role=swe), [Data Engineer](https://www.aced.io/questions?role=data-engineer), and [Machine Learning Engineer](https://www.aced.io/questions?role=ml-engineer)
- **Companies:** [Tesla](https://www.aced.io/questions?company=tesla), [Meta](https://www.aced.io/questions?company=meta-facebook), [Oracle](https://www.aced.io/questions?company=oracle), [Walmart Labs](https://www.aced.io/questions?company=walmart-labs), [TikTok](https://www.aced.io/questions?company=tiktok), [Adobe](https://www.aced.io/questions?company=adobe), and [Goldman Sachs](https://www.aced.io/questions?company=goldman-sachs)

No answers have been contributed by the community yet.

## Interview experience

One interview experience is shared for this question. It concerns a **Meta Software Engineer Intern** interview from **5 months ago**:

> “Basic process. I guess much shorter for interns. I think they just ranked us by their DSA scores and took on as many as their quota let them. Not too adverserial.”

[Read the shared Meta interview experience](https://www.aced.io/experiences/meta-facebook-software-engineer-intern-interview-c5f482)

![Meta company logo](https://exponent-static.s3.amazonaws.com/company_logos/meta.png)

## Related questions

- [Find quadruplets in an array with a given sum.](https://www.aced.io/questions/1129/find-quadruplets-with-given-sum)
- [Find a sorted triplet in a given array.](https://www.aced.io/questions/1135/find-sorted-triplet-in-array)
- [Given an array, find the two sum.](https://www.aced.io/questions/1164/find-two-sum)

## Related courses

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

![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)

We help candidates prepare for machine learning roles at Meta, Google, Amazon, Apple, Microsoft, Nvidia, and other companies through mock interviews, frameworks, and advice from senior candidates. Topics include ML system design, core concepts, coding, behavioral interviews, and more.

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

![Data Engineering Interview Prep](https://images.ctfassets.net/x78yjrjc11pq/5XoOCgXlGqN2fa1zaroNWd/9a2e23df48a212bc00d352873feb2d6a/Data_Engineer_Interview_Prep_Hero_Image.jpg?w=800&h=800&fm=webp&q=75)

We help candidates prepare for data engineering roles at Meta, Google, Amazon, Microsoft, Walmart, DoorDash, and other companies. Topics include data modeling, pipeline design, SQL, coding, and behavioral interviews.

## Aced interview preparation

Aced, formerly Exponent, offers interview preparation through courses, coding questions, interview experiences, practice tools, mock interviews and coaching. Our course areas include product management, software engineering, system design, data science, machine learning, data engineering, and other professional interview tracks.

---

[Read this page’s summary](https://www.aced.io/agents/api/public/v1/page-tldr?url=https%3A%2F%2Fwww.aced.io%2Fquestions%2F1127%2Ffind-triplet-with-given-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%2F1127%2Ffind-triplet-with-given-sum). Opening a form does not execute a tool.