Test cases are failing

test cases are failing please tell where I am wrong
#include

using namespace std;

int maxSubarray(int a[], int n)
{
int currentSum = 0, maxSum = a[0];

for (int i = 0; i < n; i++)
{
    currentSum = currentSum + a[i];
    if (a[i] < 0)
    {
        currentSum = 0;
    }
    maxSum = (max(maxSum, currentSum));
}
return maxSum;

}
int main()
{

int arraySize,test;


int a[100000];

int s[20],i=0,j=0,m;

cin>>test;
m=test;

while(test>0)
{

cin >> arraySize;


for (int i = 0; i < arraySize; i++)
{
    cin >> a[i];
}


s[j]=maxSubarray(a, arraySize);
j++;
test--;

}

for(int j=0;j<m;j++)
{
cout<<s[j]<<endl;
}

// cout<<s[j]<<" "<<m;
}

@anandsingh3210
please wait i am checking your code.

@anandsingh3210 i have corrected your code:


Happy Learning!!

Sir I have seen your code and its output looks like this -
2
4
1 2 3 4
10
3
-10 5 10
15

This means whenever we are given test cases we should consider that each input is given one by one because I was taking all the input at once and the storing in an array and the iterating the output am i correct?

@anandsingh3210 yes you have to print the ouput for all the inputs individually.

understood thank you

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.