Given an array of mixed positive and negative numbers, develop an algorithm to find the contiguous section with the maximum sum (e.g. for (-1, 2, 4, -9, 8) the segment (2, 4)).
Return a three-element list [start, end, sum], where start and end are inclusive indices of the selected segment. If multiple segments have the same maximum sum, return the earliest one. The reported example is reproduced verbatim; under the standard definition, [8] has sum 8, which exceeds [2, 4] with sum 6.
Input: A nonempty list of integers. Output: The selected segment's start index, end index, and sum.
Example: nums = [-2, 3, -1, 5, -6] returns [1, 3, 7] because 3 + (-1) + 5 = 7.
def max_subarray(nums):