Spiral print anticlockwise -1 test case failing

#include
using namespace std;

int main()
{
int a[1000][1000];
int m,n;
cin>>m>>n;

for(int i=0;i<m;i++){
    for(int j=0;j<n;j++){
       cin>>a[i][j];
    }
}

int sc=0,sr=0;
int ec=n-1,er=m-1;
while(sc<=ec && sr<=er){
    // left column
    for(int i=sr;i<=er;i++){
        cout<<a[i][sc]<<", ";
    }
    sc++;

	
    // bottom row;
    for(int i=sc;i<=ec;i++){
        cout<<a[er][i]<<", ";
    }
    er--;


	// right column
    if(ec>sc){
    for(int i=er;i>=sr;i--){
        cout<<a[i][ec]<<", ";
    }
    ec--;
    }
    //top row
	if(er>sr){
    for(int i=ec;i>=sc;i--){
        cout<<a[sr][i]<<", ";
    }
    sr++;
	}
}
cout<<"END";
return 0;

}

hello @eesha

check now->

This is working but can you please explain this change

@eesha
i have added comments.

a) ec>=sc indiates we still have some column left.

b) er>=sr indicates we still have some row left. (u were using er>sr , which may ignore some row)

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.