Maximum Subarray Sum
Mediumjavapythonccppjavascript
Find the maximum possible sum of a non-empty contiguous subarray of the given array.
Input Format
The first line contains an integer N. The second line contains N space-separated integers.
Output Format
Print the maximum subarray sum.
Example 1
Input
5 -2 3 -1 4 -5
Output
6
Explanation: The subarray [3, -1, 4] has the maximum sum, 6.
- 1 <= N <= 100000
- -1000000000 <= A[i] <= 1000000000