Update appNew update is available. Click here to update.
sidenav-btnClose
Topic list
Maximum Subarray Sum
MEDIUM
35 mins
664 upvotes
Dynamic Programming
Arrays
Topics (Covered in this problem)
Problem solved
Badge
Skill meter
Dynamic Programming
-
-
Arrays
-
-
Other topics
Problem solved
Badge
Skill meter
Strings
-
-
Matrices (2D Arrays)
-
-
Linked List
-
-
Sorting
-
-
Binary Search
-
-
Stacks & Queues
-
-
Trees
-
-
Graph
-
-
Greedy
-
-
Tries
-
-
SQL
-
-
Binary Search Trees
-
-
Heap
-
-
Bit Manipulation
-
-
Solve problems & track your progress
Checkout your overall progress in every topic here
Become
userLevel
Sensei
in DSA topics
Open the topic and solve more problems associated with it to improve your skills
Check out the skill meter for every topic
See how many problems you are left with to solve for cracking any stage. Score more than zero to get your progress counted.

Maximum Subarray Sum

Contributed by
Achint Narang
Medium
yellow-spark
0/80
Avg time to solve 35 mins
Success Rate 81 %
Share
664 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
Auto
copy-code
Console