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
23 changes: 23 additions & 0 deletions C++/kadane's_algo
Original file line number Diff line number Diff line change
@@ -0,0 +1,23 @@
#include<iostream>
using namespace std;
int kadanes(int array[],int length) {
int highestMax = 0;
int currentElementMax = 0;
for(int i = 0; i < length; i++){
currentElementMax =max(array[i],currentElementMax + array[i]) ;
highestMax = max(highestMax,currentElementMax);
}
return highestMax;
}
int main() {
cout << "Enter the array length: ";
int l;
cin >> l;
int arr[l];
cout << "Enter the elements of array: ";
for (int i = 0; i < l; i++) {
cin >> arr[i];
}
cout << "The Maximum Sum is: "<<kadanes(arr,l) << endl;
return 0;
}