Test Case Problem

class Solution {
public:
int maxSubarraySumCircular(vector& a) {
int size=a.size();
int currsum=a[0];
int candidate1=a[0];
for(int i=1;i<size;i++)
{
currsum=max(currsum+a[i],a[i]);
candidate1=max(currsum,candidate1);
}
int cumsum=0;
for(int i=0;i<size;i++)
{
cumsum+=a[i];
}
for(int i=0;i<size;i++)
{
a[i]=(-a[i]);
}
currsum=a[0];
int candidate2=a[0];
for(int i=1;i<size;i++)
{
currsum=max(currsum+a[i],a[i]);
candidate2=max(currsum,candidate2);
}
int candidate2final;
candidate2final=cumsum-(-candidate2);
return max(candidate1,candidate2final);

}

};

It Doesnt Pass this Test Case
[-2,-3,-1]
Output 0
Expected -1

@D19CPPP0005
Hello Saurav,
yeah u r right, it will give wrong answer because kadane will only work when there exist atleast one non negative number. here in ur test case all elements are negative thats why it fails

I hope I’ve cleared your doubt. I ask you to please rate your experience here
Your feedback is very important. It helps us improve our platform and hence provide you
the learning experience you deserve.

On the off chance, you still have some questions or not find the answers satisfactory, you may reopen
the doubt.