Maximum Subarray Sum
InterviewTime limit1sMemory limit128 MB
Given up to 100,000 integers, compute the maximum sum of a non-empty contiguous subarray.
- Level
Easy3 of 10
- Topics
- Dynamic programming, Array
- Solved
- No attempts yet
Problem
You are given a sequence of n integers. Find the maximum possible sum obtainable by choosing one or more consecutive elements of the sequence.
Input
The first line contains an integer n (1 ≤ n ≤ 100,000).
The second line contains n integers separated by spaces. Each integer is between -1,000 and 1,000, inclusive.
Output
Print the maximum sum obtainable by choosing one or more consecutive elements.