# Copy a Spiral Matrix

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/3058/copy-spiral-matrix
Source observed: 2026-11-05T00:28:05.126Z
Last checked: 2026-11-05T00:28:05.126+00:00
Indexed: 2026-11-06T04:32:10.746+00:00

---

# Copy a Spiral Matrix

**Difficulty:** Medium

[Unlock detailed company statistics for this question](https://www.aced.io/upgrade?src=questions)

## Problem

Given a 2D array of integers named `inputMatrix`, create a function `spiralCopy` that:

- Copies the values of `inputMatrix` into a 1D array in clockwise spiral order.
- Returns the 1D array.

## Example

**Input:**

```text
inputMatrix = [
  [1,  2,  3,  4,  5],
  [6,  7,  8,  9, 10],
  [11, 12, 13, 14, 15],
  [16, 17, 18, 19, 20]
]
```

**Output:**

```text
[1, 2, 3, 4, 5, 10, 15, 20, 19, 18, 17, 16, 11, 6, 7, 8, 9, 14, 13, 12]
```

## Practice controls

We provide Question, Solution, and Community views, along with hints and challenges. The page labels this question under [Data Structures & Algorithms](https://www.aced.io/questions?type=algorithms) and [Coding](https://www.aced.io/questions?type=coding). The question metadata shows one interview and reports that it was last asked 3 years ago.

No community answers are currently shown. The code editor includes Editor, Share, Output, Test Results, and Console panels. [Sign up to run code](https://www.aced.io/signup?src=lesson).

---

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