Sign in $ create-account
~/problems ~/discussion ~/contests ~/submission
← ~/problems
P2001

Maximum Subarray

Medium
// Description
Given an array of n integers, find the contiguous subarray (containing at least one number) with the largest sum and output that sum.
// Input
The first line contains an integer n (1 <= n <= 10^5). The second line contains n integers a_i (-10^4 <= a_i <= 10^4).
// Output
A single integer: the maximum subarray sum.
// Hint
Kadanes algorithm runs in O(n).
// Samples
Sample Input
9
-2 1 -3 4 -1 2 1 -5 4
Sample Output
6
// Problem Info
DifficultyMedium
Acceptance50%
Time Limit1000 ms
Memory Limit65536 KB
Accepted5
Dynamic Programming
// Discussion

No Discussion