Given an array, how would you find the subarray with the maximum sum efficiently? Implement the solution using a single pass through the array. Given a non-empty list of integers, return [maximum_sum, start_index, end_index]; if multiple subarrays have the same sum, return the one with the earliest start index. The subarray must be contiguous.
def max_subarray(nums):