Skip to content

Instantly share code, notes, and snippets.

@nerohoop
Created July 22, 2017 08:48
Show Gist options
  • Save nerohoop/0968d80c080fa8de4b28f618bbf47d44 to your computer and use it in GitHub Desktop.
Save nerohoop/0968d80c080fa8de4b28f618bbf47d44 to your computer and use it in GitHub Desktop.
int max_so_far = INT_MIN;
int max_end_here = 0;
for(int i=0; i<size; i++) {
max_end_here += A[i];
max_so_far = MAX(max_end_here, max_so_far);
max_end_here = MAX(0, max_end_here);
}
int maxNonCon = A[0];
for(int i=1; i<size; i++) {
maxNonCon = MAX(maxNonCon, MAX(maxNonCon + A[i], A[i]));
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment