#include
using namespace std;
int main() {
int m,n;
cin>>m>>n;
int a[10][10];
for(int i=0;i<m;i++){
for(int j=0;j<n;j++){
cin>>a[i][j];
}
}
int sc=0;
int sr=0;
int ec=n-1;
int er=m-1;
while(sr<=er && sc<=ec){
for(int i=sr;i<=er;i++){
cout<<a[i][sc]<<",";
}
sc++;
for(int j=sc;j<=ec;j++){
cout<<a[er][j]<<",";
}
er–;
if(er>=sr){
for(int i=er;i>=sr;i–){
cout<<a[i][ec]<<",";
}
ec–;
}
if(sc<=ec){
for(int j=ec;j>=sc;j–){
cout<<a[sr][j]<<",";
}
sr++;
}
}
cout<<“END”;
return 0;
}
Why failing testcases?
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.