#include
using namespace std;
int kadane(int a[],int n)
{
int cs=0,ms=0;
for(int i=0;i<n;i++)
{
cs=cs+a[i];
if(cs<0)
{
cs=0;
}
ms=max(ms,cs);
}
return ms;
}
int circularsum(int a[],int n)
{
int c1=kadane(a,n);
int c2=0;
for(int i=0;i<n;i++)
{
c2=c2+a[i];
a[i]=-a[i];
}
c2=c2+ kadane(a,n);
return (c2>c1)?c2:c1;
}
int main()
{
int n,k,t;
cin>>t;
for(k=0;k<t;k++)
{
cin>>n;
int a[1000];
for(int i=0; i<n; i++)
{
cin>>a[i];
}
cout<<circularsum(a,n);
}
return 0;
}
In circulararray it is getting failed in testcases,whats the error
hello @sneha23
please save ur code here->https://ide.codingblocks.com/
and share the generated link with me
sorry i m not able to generate the link frim can u pls tell how to do tht
go to this link -> https://ide.codingblocks.com/
paste ur code
click on file option (present on top )
there u will get save option.
press on save .
a link will be generated in ur search bar.
copy that link and share it with me
print output for each test case in separate line.
ur corrected code link -> https://ide.codingblocks.com/s/339054
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.