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
.

AnswerBot
4mo
Find the sum of the subarray with the maximum sum among all subarrays in an array of integers.
Use Kadane's algorithm to find the maximum subarray sum efficiently.
Initialize two variables, one for curr...read more
Help your peers!
Add answer anonymously...
Nagarro Software Developer Intern interview questions & answers
A Software Developer Intern was asked Q. Word Break Problem Statement You are given a list of N strings called A. Your ta...read more
A Software Developer Intern was asked Q. Sort 0 and 1 Problem Statement Given an integer array ARR of size N containing o...read more
A Software Developer Intern was asked Q. Check If Binary Representation of a Number is Palindrome Given an integer N, det...read more
Popular interview questions of Software Developer Intern
A Software Developer Intern was asked Q1. Word Break Problem Statement You are given a list of N strings called A. Your ta...read more
A Software Developer Intern was asked Q2. Sort 0 and 1 Problem Statement Given an integer array ARR of size N containing o...read more
A Software Developer Intern was asked Q3. Check If Binary Representation of a Number is Palindrome Given an integer N, det...read more
Stay ahead in your career. Get AmbitionBox app


Trusted by over 1.5 Crore job seekers to find their right fit company
80 L+
Reviews
10L+
Interviews
4 Cr+
Salaries
1.5 Cr+
Users
Contribute to help millions
AmbitionBox Awards
Get AmbitionBox app

