BackeasyArrays

Max Subarray Sum Solution

Problem Statement

You are given an array of integers. Find the maximum contiguous subarray sum. If the array is empty, return 0.

Example 1
Input
[5, 3, 8, 1]
Output
11

Explanation: The maximum subarray sum is 11, in the subarray [8, 3]

Example 2
Input
[-2, -3, 4, -1, -2, 1, 5, -3]
Output
7

Explanation: The maximum subarray sum is 7, in the subarray [1, 5, -3]

Example 3
Input
[]
Output
0

Explanation: The maximum subarray sum is 0 for an empty array

Constraints

  • You can assume the input array is non-null. The integers in the array can be positive, negative, or zero.
Live Compiler
Loading...
Test Cases & Output
🔒 Sign up to run your code

🚀 Practice this problem

Run code, get AI hints & track streak

Sign Up Free