Skip to content
Open
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
47 changes: 47 additions & 0 deletions Algorithms/Kadane.c
Original file line number Diff line number Diff line change
@@ -0,0 +1,47 @@
/*
* CODE SUBMITTED BY- SUBHAM SAHU
* GITHUB URL - https://github.com/subhamx
* LINKED URL - https://www.linkedin.com/in/subhamX/
*
*/


/*

INPUT FORMAT -
SIZE OF ARRAY
ARRAY ELEMENTS

OUTPUT FORMAT -
MAXIMUM SUM OF SUBARRAY

*/

#include<stdio.h>
#include<limits.h>

int main(){
int n, temp;
scanf("%d", &n);
int A[n];
for(int i=0; i<n; i++){
scanf("%d", A+i);
}
int ans = INT_MIN;
temp = 0;
for(int i=0; i<n; i++){
temp += A[i];
if(temp>ans){
ans=temp;
}
if(temp<0){
temp=0;
}
}
printf("%d\n", ans);
}

/*
ANALYSIS -
This Algorithm returns the maximum sum in O(n).
*/