#include
#include
using namespace std;
int maxsubarray(int a[],int n)
{
int currsum=0;
int maxsum=0;
for(int i=0;i<n;i++)
{
currsum=currsum+a[i];
if(currsum<0)
{
currsum=0;
}
maxsum=max(maxsum,currsum);
}
return maxsum;
}
int main()
{
int num,n;
int a[10000];
cin>>num;
for(int i=0;i<num;i++)
{
cin>>n;
for(int j=0;j<n;j++)
{
cin>>a[j];
}
cout<<maxsubarray(a,n)<<endl;
}
}
What wrong in this code
Hi @Adityakumar3112
change the size of array a to 100000 as the constraints given in the question are this big. This will give the correct answer.
Hope it Helps.