MCPcopy Create free account
hub / github.com/codemistic/Data-Structures-and-Algorithms / kadane

Function kadane

CPP/array-2d/kadane_algo.cpp:3–15  ·  view source on GitHub ↗

Source from the content-addressed store, hash-verified

1#include<bits/stdc++.h>
2using namespace std;
3int kadane(int arr[], int n){
4 int current=0;
5 int largest=0;
6 for (int i = 0; i < n; ++i)
7 {
8 current+=arr[i];
9 if(current<0){
10 current=0;
11 }
12 largest= max(current,largest);
13 }
14 return largest;
15}
16void initial(){
17 #ifndef ONLINE_JUDGE
18 freopen("input.txt", "r", stdin);

Callers 1

mainFunction · 0.85

Calls 1

maxFunction · 0.70

Tested by

no test coverage detected