
Asked in Amazon and 46 others
Given an integer array nums, find the contiguous subarray (containing at least one number) which has the largest sum and return its sum.
Anonymous
1mo
Using an efficient algorithm
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<n; i++){
sum = max(sum+arr[i] , arr[i]);
res = max(sum , res);
}
re...read more
Anonymous
4y
I used Kadane's algorithm for solving this problem.
Add answer anonymously...
Interview Questions from Popular Companies

3.7
• 8.7k Interviews

4.0
• 5.4k Interviews

3.5
• 4.2k Interviews

3.6
• 8k Interviews

3.7
• 6k Interviews

3.7
• 6.2k Interviews

3.5
• 4.2k Interviews

3.7
• 5.1k Interviews
Stay ahead in your career. Get AmbitionBox app


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
AmbitionBox Awards
Get AmbitionBox app

