Maximum Sum Subarray Problem Statement
Given an array of integers, find the maximum sum of any contiguous subarray within the array.
Example:
Input:
array = [34, -50, 42, 14, -5, 86]
Output:
137
Explanation:
The maximum sum of a contiguous subarray is 137, which is the sum of the elements [42, 14, -5, 86].
Input:
array = [-5, -1, -8, -9]
Output:
-1
Explanation:
The maximum sum of a contiguous subarray is -1, as choosing any subarray cannot yield a greater sum.
Input:
N
array of N space-separated integers
Output:
Maximum sum of any contiguous subarray
Constraints:
- 1 ≤ N ≤ 105
- -104 ≤ array[i] ≤ 104
Note:
The solution should be accomplished in O(N) time complexity.
Be the first one to answer
Add answer anonymously...
Top Directi Software Developer interview questions & answers
Popular interview questions of Software Developer
Top HR questions asked in Directi 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