MCPcopy Create free account
hub / github.com/Lakhankumawat/LearnCPP / maxSubArraySum3

Function maxSubArraySum3

A-Array/MaximumSumSubarray.cpp:54–68  ·  view source on GitHub ↗

kadene's algorithm

Source from the content-addressed store, hash-verified

52
53//kadene's algorithm
54int maxSubArraySum3(int a[],int n)
55{
56 int currsum=0;
57 int maxSum=INT_MIN;
58 for(int i=0;i<n;i++)
59 {
60 currsum+=a[i];
61 if(currsum<0)//keep on updting currsum if its less than zero.
62 {
63 currsum=0;
64 }
65 maxSum=max(maxSum,currsum);
66 }
67 return maxSum;
68}
69
70int main() {
71 int n;

Callers 1

mainFunction · 0.85

Calls 1

maxFunction · 0.50

Tested by

no test coverage detected