Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Add files and Readme #90

Open
wants to merge 2 commits into
base: main
Choose a base branch
from
Open
Show file tree
Hide file tree
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
27 changes: 27 additions & 0 deletions MaxSubarray.cpp
Original file line number Diff line number Diff line change
@@ -0,0 +1,27 @@
#include <iostream>
using namespace std;

// function for kadane's algorithm
static int kadane(int Array[], int n) {
int max_sum = 0;
int current_sum = 0;

for(int i=0; i<n; i++) {
current_sum = current_sum + Array[i];

if (current_sum < 0)
current_sum = 0;

if(max_sum < current_sum)
max_sum = current_sum;
}
return max_sum;
}

// test the code
int main() {
int MyArray[] = {-3, 1, -8, 12, 0, -3, 5, -9, 4};
int n = sizeof(MyArray) / sizeof(MyArray[0]);
cout<<"Maximum SubArray is: "<<kadane(MyArray, n);
return 0;
}
1 change: 1 addition & 0 deletions README.md
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
# Programming_Hactoberfest23