# Move all zeros to the end of an array | 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/968/move-zeros-to-end-array
Source observed: 2026-11-04T22:21:40.271Z
Last checked: 2026-11-04T22:21:40.271+00:00
Indexed: 2026-11-05T20:31:56.627+00:00

---

# Move all zeros to the end of an array

**Difficulty:** Easy  
**Category:** [Data Structures & Algorithms](https://www.aced.io/questions?type=algorithms&filterBy=codeEditor&src=nav)  
**Reported interviews:** 10  
**Reported last asked:** 2 months ago, as observed on 2026-11-04  
**Save count:** 151

We provide this coding question for interview preparation. It asks you to write a function that moves every zero in an unsorted integer array to the end while preserving the relative order of all non-zero elements.

## Constraints

- Perform the transformation **in place** without making a copy of the array.
- Minimize the total number of operations.

## Example

Given:

```text
[0, 1, 0, 3, 12]
```

After the function runs:

```text
[1, 3, 12, 0, 0]
```

## Additional examples

```text
arr = [0, 1, 0, 3, 12]
output: [1, 3, 12, 0, 0]

arr = [1, 2, 0, 4, 3, 0, 5, 0]
output: [1, 2, 4, 3, 5, 0, 0, 0]

arr = [1]
output: [1]

arr = [0, 0, 1]
output: [1, 0, 0]
```

## Available question views

The question interface includes **Question**, **Solution**, **Mock Interview**, and **Community** views. The solution and mock-interview views are locked in the supplied interface. The community area is labeled with 109 contributions, while no community answers are included in the supplied content.

The coding workspace offers Python selection, an editor, sharing, output, test results, and console areas. Running code requires [signing up](https://www.aced.io/signup?src=lesson).

## Interview experiences

We include three shared interview experiences related to this question:

1. [TikTok — Site Reliability Engineer, Entry Level / L3](https://www.aced.io/experiences/tiktok-site-reliability-engineer-interview-591119), shared 2 months ago. The contributor wrote: “I would say the phone call with recruiter is just discussion on the role and scheduling the coding interview. The coding interview is on hackerrank and 1 - 2 leetcode medium problems.”
2. [Meta — Site Reliability Engineer, Entry Level / L3](https://www.aced.io/experiences/meta-facebook-site-reliability-engineer-interview-129c6b), shared 4 months ago. The contributor wrote: “Very rigorous. Interviewers were in a rush. I believe it’s crucial to get a feel of what you should expect during the interview and what kinds of signals you need to give. So I strongly recommend scheduling mock interviews with peers or, much more preferably, actual google or Facebook employees.”
3. [Nordstrom — Software Engineer, Senior / L5](https://www.aced.io/experiences/nordstrom-senior-software-engineer-interview-c92e08), shared 7 months ago. The contributor wrote: “Ok! The interview quality was bad, they do not hire much, and their tech stack is not on par with the market.”

The question is also categorized for these roles: [Software Engineer](https://www.aced.io/questions?role=swe), [Site Reliability Engineer](https://www.aced.io/questions?role=sre), [Machine Learning Engineer](https://www.aced.io/questions?role=ml-engineer), [Data Engineer](https://www.aced.io/questions?role=data-engineer), and [Data Scientist](https://www.aced.io/questions?role=data-science). Company associations shown include [Meta](https://www.aced.io/questions?company=meta-facebook), [TikTok](https://www.aced.io/questions?company=tiktok), [Nordstrom](https://www.aced.io/questions?company=nordstrom), [Amazon](https://www.aced.io/questions?company=amazon), and [Apple](https://www.aced.io/questions?company=apple).

## Related question

- [Given an array of integers, print all subarrays that sum to zero.](https://www.aced.io/questions/964/subarrays-with-zero-sum)

## Related courses

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

We offer preparation for machine-learning roles at Meta, Google, Amazon, Apple, Microsoft, Nvidia, and other top companies, including mock interviews, frameworks, senior-candidate advice, ML system design, core concepts, coding, and behavioral interviews.

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

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

We offer preparation for data-science roles at Google, Amazon, Microsoft, Meta, Apple, and other top companies, covering statistics, experimentation, coding, SQL, machine learning, behavioral interviews, mock interviews, frameworks, and advice from senior candidates.

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

---

[Read this page’s summary](https://www.aced.io/agents/api/public/v1/page-tldr?url=https%3A%2F%2Fwww.aced.io%2Fquestions%2F968%2Fmove-zeros-to-end-array&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%2F968%2Fmove-zeros-to-end-array). Opening a form does not execute a tool.