2. Find the maximum subarray sum given an array with positive and negative integers.

AnswerBot
1y

Find the maximum subarray sum in an array with positive and negative integers.

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

  • Initialize two variables, one for current maximum and one for glob...read more

Anonymous
3y

// Kadane's algorithm

int maxSum(int arr[] , int n){

int sum;

int res;

sum = arr[0];

res = arr[0];

for(int i=1; i

sum = max(sum+arr[i] , arr[i]);

res = max(sum , res);

}

re...read more

Anonymous
3y
I used Kadane's algorithm for solving this problem.
Add answer anonymously...
Infosys Specialist Programmer Interview Questions
Stay ahead in your career. Get AmbitionBox app
qr-code
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

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

Follow us
  • Youtube
  • Instagram
  • LinkedIn
  • Facebook
  • Twitter