Maximum Subarray Sum

Easy
arrays Google Amazon Meta

Find the contiguous subarray within a one-dimensional array of numbers which has the largest sum (Kadane's algorithm).

Example

max_subarray_sum([-2, 1, -3, 4, -1, 2, 1, -5, 4])
# => 6  (subarray [4, -1, 2, 1])

Test Cases

Python Editor

Output

Click "Run" to see results...