Maximum Subarray
Problem statement
Given a nonempty integer array nums, return the largest sum of any nonempty contiguous subarray. A subarray uses consecutive elements in their original order.
For this exercise, assume the result is an exact signed 64-bit integer. You must choose at least one element, including when all values are negative.
Function
maxSubarraySum(nums: int[]) → longExamples
Example 1
nums = [-2,1,-3,4,-1,2,1,-5,4]return = 6Interior maximum across several positive runs.
Example 2
nums = [-8,-3,-6]return = -3All negative must not return empty zero.
Example 3
nums = [5]return = 5Single positive.
Constraints
1 <= nums.length <= 1000.-10^9 <= nums[i] <= 10^9.- Use signed 64-bit arithmetic for running sums and the result.