MCPcopy Create free account
hub / github.com/Vishruth-S/CompetitiveCode / main

Function main

GeeksForGeeks/Kadane's Algorithm/solution.cpp:4–27  ·  view source on GitHub ↗

Source from the content-addressed store, hash-verified

2using namespace std;
3
4int main() {
5 int t;
6 cin>>t; //no. of testcases
7 while(t!=0)
8 {
9 int n;
10 cin>>n; //enter size of array
11 int i, e=0, f=INT_MIN, arr[n];
12 for(i=0; i<n; i++)
13 cin>>arr[i]; //take array input
14 for(i=0; i<n; i++)
15 {
16 e=e+arr[i]; //to get maximum contiguous sum of array
17 if(f<e)
18 f=e; //updating f with maximum possible sum value
19 if(e<0) //if sum (e) happens to be negative then reintialize sum (e) = 0
20 e=0;
21 }
22 cout<<f<<endl;
23 t--;
24
25 }
26 return 0;
27}

Callers

nothing calls this directly

Calls

no outgoing calls

Tested by

no test coverage detected