New update is available. Click here to update.
sidenav-btnClose
Topic list
Maximum Subarray Sum
HARD
35 mins
617 upvotes
Dynamic Programming
Arrays
Topics (Covered in this problem)
Problem solved
Skill meter
Dynamic Programming
-
Arrays
-
Other topics
Problem solved
Skill meter
Strings
-
Matrices (2D Arrays)
-
Sorting
-
Binary Search
-
Linked List
-
Stacks & Queues
-
Trees
-
Graph
-
Greedy
-
Tries
-
Binary Search Trees
-
Heap
-
Bit Manipulation
-

Maximum Subarray Sum

Contributed by
Achint Narang
Hard
Avg time to solve 35 mins
Success Rate 81 %
Share
617 upvotes

Problem Statement

You are given an array (ARR) of length N, consisting of integers. You have to find the sum of the subarray (including empty subarray) having maximum sum among all subarrays.

A subarray is a contiguous segment of an array. In other words, a subarray can be formed by removing 0 or more integers from the beginning, and 0 or more integers from the end of an array.

Note :
The sum of an empty subarray is 0.
Detailed explanation ( Input/output format, Notes, Constraints, Images )
Sample Input 1 :
9
1 2 7 -4 3 2 -10 9 1
Sample Output 1 :
11
Explanation for Sample 1 :
The subarray yielding maximum sum is [1, 2, 7, -4, 3, 2].
Sample Input 2 :
6
10 20 -30 40 -50 60
Sample Input 2 :
60
Sample Input 3 :
3
-3 -5 -6
Sample Input 3 :
0
Reset Code
Full screen
copy-code
Console