Maximum subarray sum :- run error

#include
using namespace std;
int main(){

int count =0;

int test;
cin>>test;

while(1){
int n;
cin>>n;

int max=0;

 int a[1000];

for(int i=0;i<n;i++){
	cin>>a[i];
}
for(int i=0;i<n;i++){
	for(int j=i;j<n;j++){
			int current=0;
		for(int k=i;k<=j;k++){
			current=a[k]+current;
		}
		if(current>max){
			max=current;
		}
	}
}
cout<<max;
count++;
cout<<endl;

if(count==test){
	break;
}	

}

return 0;

	}

hello @vanshit02

pls save ur code at cb ide and share its link with me

check now-

optimise this code to pass all testcode

still the same “TLE”

Solve it in O(n) to pass test cases

hey aman can u send me the code cause I’m stuck here !!

u need to learn about kadane algorithm to solve this problem.

it is covered in the same playlist pls watch it and try again

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.