2d anticlock wise print..test case 3 is wrong answer why

#include
using namespace std;
void anti_clock_spiral(int arr[][1000],int m,int n){
int sr=0;
int sc=0;
int er=m-1;
int ec=n-1;
while(sr<=er && sc<=ec){
for(int i=sr;i<=er;i++){
cout<<arr[i][sc]<<", ";

}
sc++; 
for(int j=sc;j<=ec;j++){
	cout<<arr[er][j]<<", ";

}
er--;
if(ec>sc){
for(int i=er;i>=sr;i--){
	cout<<arr[i][ec]<<", ";

}
ec--;
}
if(sr<er){
for(int j=ec;j>=sc;j--){
	cout<<arr[sr][j]<<", ";

}
sr++;
}


}

}
int main() {
int m,n;
cin>>m>>n;
int arr[m][1000]={0};
for(int i=0;i<m;i++){
for(int j=0;j<n;j++){
cin>>arr[i][j];
}
}
anti_clock_spiral(arr,m,n);
cout<<" END";
return 0;
}

hi @kumawatnitesh093, use <= in if condition

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.