Maximum Subarray Sum Problem Statement

Given an array ARR consisting of N integers, your goal is to determine the maximum possible sum of a non-empty contiguous subarray within this array.

Example of Subarrays:

An array C is considered a subarray of array D if it can be obtained by deleting zero or more elements from the beginning and end of the array D. For instance, for the array [1, 2, 3], all non-empty subarrays are [1], [2], [3], [1, 2], [2, 3], and [1, 2, 3].

Input:

N
ARR[0] ARR[1] ... ARR[N-1]

Output:

Print the maximum possible sum of any subarray of the array/list.

Example:

Input:
5
-2 1 -3 4 -1
Output:
4
Explanation:

The subarray [4] has the maximum sum of any contiguous subarray.

Constraints:

  • 1 <= N <= 5*105
  • -109 <= ARR[i] <= 109
  • Time Limit: 1 second

Note:

You do not need to print anything; it has already been taken care of. Implement the required function to find the solution.

AnswerBot
4mo

Find the maximum sum of a contiguous subarray in an array of integers.

  • Use Kadane's algorithm to find the maximum subarray sum efficiently.

  • Initialize two variables: maxEndingHere and maxSoFar.

  • Iterate t...read more

Help your peers!
Select
Add answer anonymously...

Accenture Software Developer interview questions & answers

A Software Developer was asked 1w agoQ. Describe the SOLID principles.
A Software Developer was asked 4mo agoQ. What is polymorphism?
A Software Developer was asked 4mo agoQ. What design software do you know?

Popular interview questions of Software Developer

A Software Developer was asked 1w agoQ1. Describe the SOLID principles.
A Software Developer was asked 4mo agoQ2. What design software do you know?
A Software Developer was asked 4mo agoQ3. Define the tree data structure.

Top HR questions asked in Accenture Software Developer

A Software Developer was asked 1w agoQ1. Explain your projects.
A Software Developer was asked 1mo agoQ2. Why do you believe I am required in the company?
A Software Developer was asked 2mo agoQ3. What motivates you to choose a career in the software development field?
Accenture Software Developer Interview Questions
Stay ahead in your career. Get AmbitionBox app
play-icon
play-icon
qr-code
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

Made with ❤️ in India. Trademarks belong to their respective owners. All rights reserved © 2025 Info Edge (India) Ltd.

Follow Us
  • Youtube
  • Instagram
  • LinkedIn
  • Facebook
  • Twitter
Profile Image
Hello, Guest
AmbitionBox Employee Choice Awards 2025
Winners announced!
awards-icon
Contribute to help millions!
Write a review
Write a review
Share interview
Share interview
Contribute salary
Contribute salary
Add office photos
Add office photos
Add office benefits
Add office benefits