Maximum Subarray Sum Problem Statement

Given an array of numbers, the task is to find the maximum sum of any contiguous subarray of the array.

Input:

The first line of input contains the size of the array, denoted by N. The second line contains N space-separated integers representing the array elements.

Output:

The first and only line of output should print the maximum subarray sum.

Example:

Input:
6
34 -50 42 14 -5 86
Output:
137
Explanation:

The maximum sum is 137, achieved by summing the subarray [42, 14, -5, 86].

Input:
4
-5 -1 -8 -9
Output:
-1
Explanation:

The maximum sum is -1, which is just the largest number in this case.

Constraints:

  • The solution should be implemented in O(N) time.
  • N can be large, so efficient solutions are favorable.
Note:

Consider edge cases such as all numbers being negative.

AnswerBot
4mo

Find the maximum sum of any contiguous subarray in an array of numbers in O(N) time.

  • Use Kadane's algorithm to find the maximum subarray sum in O(N) time.

  • Initialize two variables: maxEndingHere and max...read more

Help your peers!
Select
Add answer anonymously...

Paytm Software Developer interview questions & answers

A Software Developer was asked 4mo agoQ. Given a sorted array of integers nums and an integer target, write a function to...read more
A Software Developer was asked 6mo agoQ. What is multithreading?
A Software Developer was asked 7mo agoQ. Given a 2D grid map of '1's (land) and '0's (water), count the number of islands...read more

Popular interview questions of Software Developer

A Software Developer was asked 4mo agoQ1. Given a sorted array of integers nums and an integer target, write a function to...read more
A Software Developer was asked 6mo agoQ2. What is multithreading?
A Software Developer was asked 7mo agoQ3. Given a 2D grid map of '1's (land) and '0's (water), count the number of islands...read more
Paytm 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