How would you implement the Kadane algorithm?
Implement max_subarray(nums), which returns the maximum possible sum of any non-empty contiguous subarray. The input is a non-empty list of integers, and the output is an integer. Handle arrays containing only negative values.
def max_subarray(nums):