Spiral print not working for a particular test case

My code is not working for the test case:

3 2

11 12

21 22

31 32

Am I missing something??

My code:-

int main() {

int n, m;
cin>>n>>m;
int a[n][m];
for(int i=0; i<n; i++){
	for(int j=0; j<m; j++){
		cin>>a[i][j];
	}
}
int top=0, bottom=n-1, left=0, right=m-1;
while(top<=bottom and left<=right){
	for(int row=top; row<=bottom; row++){
		cout<<a[row][left]<<", ";
	}
	left++;
	for(int col=left; col<=right; col++){
		cout<<a[bottom][col]<<", ";
	}
	bottom--;
	if(right>left){
		for(int row=bottom; row>=top; row--){
			cout<<a[row][right]<<", ";
		}
		right--;
	}
	if(bottom>top){
		for(int col=right; col>=left; col--){
			cout<<a[top][col]<<", ";
		}
		top++;
	}
}
cout<<"END";
return 0;

}

hello @antriksh_mangal
check now->

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.