Maximum Subarray Sum Problem Statement
Given an array arr
of length N
consisting of integers, find the sum of the subarray (including empty subarray) with the maximum sum among all subarrays.
Explanation:
A subarray is a contiguous segment of an array, meaning it can be formed by removing 0 or more integers from the start, and 0 or more integers from the end of the array.
Input:
N
arr[0] arr[1] ... arr[N-1]
Output:
The sum of the maximum subarray.
Example:
Input:
N = 5
arr = [-2, 1, -3, 4, -1]
Output:
4
Explanation:
The maximum subarray sum is obtained by the subarray [4]
which has the sum 4
.
Constraints:
1 <= N <= 10^6
-10^6 <= arr[i] <= 10^6
Note:
The sum of an empty subarray is considered 0
.
Be the first one to answer
Add answer anonymously...
Top Siemens Software Developer interview questions & answers
Popular interview questions of Software Developer
Top HR questions asked in Siemens Software Developer
Stay ahead in your career. Get AmbitionBox app
Helping over 1 Crore job seekers every month in choosing their right fit company
65 L+
Reviews
4 L+
Interviews
4 Cr+
Salaries
1 Cr+
Users/Month
Contribute to help millions
Get AmbitionBox app