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;
}