# Problem

> This problem was asked by Facebook.
>
> Given a circular array, compute its maximum subarray sum in O(n) time. A subarray can be empty, and in this case the sum is 0.
>
> For example, given `[8, -1, 3, 4]`, return `15` as we choose the numbers `3`, `4`, and `8` where the `8` is obtained from wrapping around.
>
> Given `[-4, 5, 1, 0]`, return `6` as we choose the numbers `5` and `1`.

**Example 1:**

<pre><code><strong>Input: nums = [1,-2,3,-2]
</strong><strong>Output: 3
</strong><strong>Explanation: Subarray [3] has maximum sum 3.
</strong></code></pre>

**Example 2:**

<pre><code><strong>Input: nums = [5,-3,5]
</strong><strong>Output: 10
</strong><strong>Explanation: Subarray [5,5] has maximum sum 5 + 5 = 10.
</strong></code></pre>

**Example 3:**

<pre><code><strong>Input: nums = [-3,-2,-3]
</strong><strong>Output: -2
</strong><strong>Explanation: Subarray [-2] has maximum sum -2.
</strong></code></pre>

\\

what do we need?

* iterate
* track sum?

{% embed url="<https://leetcode.com/problems/maximum-subarray/description/>" %}


---

# Agent Instructions: Querying This Documentation

If you need additional information that is not directly available in this page, you can query the documentation dynamically by asking a question.

Perform an HTTP GET request on the current page URL with the `ask` query parameter:

```
GET https://algorithm.prettylog.com/algorithm-problems/daily-algorithms/4.-maximum-sub-array-sum/problem.md?ask=<question>
```

The question should be specific, self-contained, and written in natural language.
The response will contain a direct answer to the question and relevant excerpts and sources from the documentation.

Use this mechanism when the answer is not explicitly present in the current page, you need clarification or additional context, or you want to retrieve related documentation sections.
