Problem with Kadane Algorithm

#include
using namespace std;
int main() {

int t;
while(t!=0)
{
int n;
int arr[n];

   for(int i=0;i<n;i++)
   {
	   cin>>arr[i];
	   cout<<" ";
   }

   int cs=0;
   int ms=0;

   for(int i=0;i<n;i++)
   {
	   cs+=arr[i];

	   if(cs<0)
	   {
		   cs=0;
	   }

	   else
	   {
		   ms=max(ms,cs);
	   }
   }

   cout<<ms;

}
t–;
return 0;
}

Hey @arsh_goyal
You are not taking input N ( size of the array ) before assigning a size of arr. Rest is fine.

If your doubt is resolved please mark it as closed.

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.

@arsh_goyal you opened the doubt again. What would you like me to help you with ?

#include using namespace std; int main() { int t; while(t>=0) { int n; cin>>n; int arr[n]; for(int i=0;i<n;i++) { cin>>arr[i]; } int cs=0,ms=0; for(int i=0;i<n;i++) { cs+=arr[i]; if(cs<0) { cs=0; } ms=max(cs,ms); } cout<<ms<<endl; t–; }

Again you have not taken
cin>>t
And please paste it on CB IDE or IDEONE and then send code.

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.