Test case 2 fail

#include
using namespace std;
int main() {
int m,n;
cin>>m>>n;
int arr[1000][1000];

for(int i=0;i<m;i++)
{
	for(int J=0;J<n;J++)
	cin>>arr[i][J];
}
int startrow=0;
int endrow=m-1;
int startcol=0;
int endcol=n-1;

while((startrow<=endrow)&&(endcol>=startcol))
{   if(startcol<endcol)
    {
	for(int i=startrow;i<=endrow;i++)
	cout<<arr[i][startcol]<<", ";
	}

	startcol++;
    if(endrow>startrow)
	{
	for(int j=startcol;j<=endcol;j++)
	cout<<arr[endrow][j]<<", ";
	}

	endrow--;
    
	for(int i=endrow;i>=startrow;i--)
	cout<<arr[i][endcol]<<", ";

	endcol--;
    
	for(int i=endcol;i>=startcol;i--)
	cout<<arr[startrow][i]<<", ";

	startrow++;
}
cout<<"END";

return 0;

}

hello @himanshu24

pur this inside if(starcol<=endcol)

similarly

put this inside if(startrow<=endrow)

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.