Maximum Subarray Sum (Kadane's Algorithm)
M · mediumPracticearrays
Problem
Find the sum of the contiguous subarray with the maximum sum.
Example
Input
6 -2 1 -3 4 -1 2
Output
5
current_sum = max(arr[i], current_sum + arr[i]). max_sum = max(max_sum, current_sum).