# Reverse a Sentence — coding interview question

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/3062/reverse-a-sentence
Source observed: 2026-11-04T22:21:38.724Z
Last checked: 2026-11-04T22:21:38.724+00:00
Indexed: 2026-11-06T18:55:20.205+00:00

---

# Reverse a Sentence

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

## Problem

You are given an array of characters `arr` consisting of sequences of characters separated by space characters. Each space-delimited sequence defines a word. Implement `reverseWords` to reverse the order of the words in the array as efficiently as possible.

Explain the solution and analyze its time and space complexities.

## Example

```text
input:  arr = [ 'p', 'e', 'r', 'f', 'e', 'c', 't', '  ',
               'm', 'a', 'k', 'e', 's', '  ',
               'p', 'r', 'a', 'c', 't', 'i', 'c', 'e' ]

output: [ 'p', 'r', 'a', 'c', 't', 'i', 'c', 'e', '  ',
          'm', 'a', 'k', 'e', 's', '  ',
          'p', 'e', 'r', 'f', 'e', 'c', 't' ]
```

The example reverses the word order while preserving each word's characters and the separating spaces.

## Question workspace

We provide **Question**, **Solution**, and **Community** tabs. The coding workspace includes **Editor**, **Share**, **Output**, **Test Results**, and **Console** panels; running code requires [signing up](https://www.aced.io/signup?src=lesson).

Detailed company statistics are available through [Upgrade](https://www.aced.io/upgrade?src=questions).

## Interview metadata

- The question is listed for **Software Engineer** (4) and **Data Engineer** (2) roles, and also for **Data Scientist** and **Machine Learning Engineer** roles.
- Associated companies listed are **Apple** (2), **Meta**, **Intel**, **Visa**, **Adobe**, **Google**, and **Microsoft**.
- The rendered page lists **+49 interviews**, reports that it was last asked **2 years ago**, and includes a save count of **95**.
- No community answers have been contributed yet.

## Interview experience

One shared experience is associated with Meta:

> “Focusing on leetcode was sufficient, escpecially the leetcode premium. the hard part was behavioral and needed real examples”
>
> — Software Engineer · Entry Level / L3, Meta · 2 years ago

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

## Related question

- [Reverse a linked list.](https://www.aced.io/questions/3247/reverse-linked-list)

## 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 cover mock interviews, frameworks, advice from senior candidates, ML system design, core concepts, coding, and behavioral interviews for roles at Meta, Google, Amazon, Apple, Microsoft, Nvidia, and other companies.

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

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

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

## Other Aced interview-preparation areas

We organize preparation across courses and practice resources, including Product Management, Forward Deployed Engineering, Engineering Management, Software Engineering, System Design, Data Science, Machine Learning, Data Engineering, AI Engineering, Investment Banking, Generative AI, Security Engineer, TPM, Solutions Architect, UX / Product Design, and BizOps & Strategy. We also provide interview questions, practice, coaching, resume review, salary negotiation, interview experiences, job referrals, resources, and pricing information.

[Browse all questions](https://www.aced.io/questions) · [View all courses](https://www.aced.io/courses?src=nav) · [Practice](https://www.aced.io/practice?src=nav) · [Coaching](https://www.aced.io/coaching?src=nav)

---

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