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.

AnswerBot
4mo

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

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

  • Initialize max_sum and current_su...read more

Sateesh Babu
1y
1 person
Sateesh Babu
1y
The direct approach to solve this problem is to run two for loops and for every subarray check if it is the maximum sum possible. Time complexity: O(N^2), Where N is the size of the array. Space compl...read more
Select
Add answer anonymously...

Tech Mahindra Software Engineer interview questions & answers

A Software Engineer was asked 1w agoQ. How do you train a machine?
A Software Engineer was asked 2mo agoQ. What is Kotlin?
A Software Engineer was asked 2mo agoQ. Tell me about your projects and training.

Popular interview questions of Software Engineer

A Software Engineer was asked 1w agoQ1. How do you train a machine?
A Software Engineer was asked 2w agoQ2. What are the key concepts of Object-Oriented Programming, and why are they used?
A Software Engineer was asked 2w agoQ3. What is the difference between String and StringBuilder, and in what circumstanc...read more

Top HR questions asked in Tech Mahindra Software Engineer

A Software Engineer was asked 4mo agoQ1. What is your salary expectation?
A Software Engineer was asked 5mo agoQ2. Are you willing to relocate?
A Software Engineer was asked 5mo agoQ3. Can you tell me about yourself?
Tech Mahindra Software Engineer 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