# Maximum Subarray

Given an integer array `nums`, find the subarray with the largest sum and return its sum.

## Function Signature

```python
def max_subarray(nums: list[int]) -> int:
```

## Parameters
- `nums` — a non-empty list of integers

## Returns
- The maximum subarray sum

## Examples

```
max_subarray([-2,1,-3,4,-1,2,1,-5,4]) -> 6  # [4,-1,2,1]
max_subarray([1]) -> 1
max_subarray([5,4,-1,7,8]) -> 23
```
