Why this program is failing all the testcases?

#include
using namespace std;

void subArray(signed long int a[], int n){
int left=-1, right=-1;
int maxSum=0;
int currentSum=0;
static int t=1;
cout<<"for test case "<<t<<endl;
for(int i=0; i<n; i++){
currentSum+=a[i];

	if(currentSum<0){
		currentSum=0;
	}
     maxSum=max(maxSum, currentSum);
	 cout<<maxSum;
		
}
cout<<" maximum sub array sum = "<<maxSum;
for(int i=left; i<right; i++){
	cout<<a[i];
}

}

int main()
{ int nTC;

cout<<" number of testcases :";
cin>>nTC;
cout<<endl;
 for(int i=0; i<nTC; i++){
 cout<<"number of elements in array "<<i<<": ";
 int n;
 cin>>n;
 signed long int a[n];
 for(int i=0; i<n; i++){
	 cin>>a[i];
 }
 subArray(a, n);
 }
 
return 0;

}

hi @sb1251224_6919c19fccd96630
I have corrected your code… its working fine and passing all test cases…

But it is still failing all the test cases

hi @sb1251224_6919c19fccd96630
I tried submitting it… it’s passing all test cases…


maybe try refreshing the page…

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.

Please check the code given below and do tell me what is the error int this code:

#include using namespace std; int main() { int t;//number of test cases long int N;//size of the array signed long long int A[1000]; int csum=0; int maxSum=0; cin>>t; for(int i=0; i<t; i++){ cin>>N; for(int j=0; j<N; j++){ cin>>A[j]; //cout<<"\t"; } //using Kadane’s Algorithm for(int k=0; k<N; k++){ csum+=A[k]; if(csum<0){ csum=0; } maxSum=max(csum, maxSum); } } cout<<maxSum; return 0; }

hi @sb1251224_6919c19fccd96630
kindly save ur code on coding blocks ide and send link…

But I do not use coding blocks IDE, I code in visual studio code

Look at the way u have sent code in the form of paragraph… how do I debug it??

How can I share the file as the URL doesn’t get generated in coding blocks ide?

go to https://ide.codingblocks.com/
write ur code…
click CTRL + s…
share the url then…

Is it possible to share the source code file written in notepad? Then you can run the code in your compiler and debug it.

hi @sb1251224_6919c19fccd96630
i don’t understand what issue are u exactly facing… for reference also I have sent code above…

Is there any other way of sharing code and ask the doubt because I am unable to logging in the coding blocks ide and therefore not getting the link which I can share?

save it on some other online ide and maybe send link…