#include
using namespace std;
void spiral(int **arr, int n, int m){
int startRow = 0;
int startCol = 0;
int endRow = n-1;
int endCol = m-1;
while(startRow <= endRow && startCol <= endCol)
{
//first col
for(int i = startRow; i <= endRow;i++){
cout << arr[i][startCol] << ", ";
}startCol++;
//end row
for(int i = startCol; i <= endCol;i++){
cout << arr[endRow][i] << ", ";
}endRow--;
//last col
if(endCol > startCol){
for(int i = endRow;i >= startRow; i--){
cout << arr[i][endCol] << ", ";
}endCol--;
}
if(endRow > startCol){
for(int i = endCol; i >= startCol;i--){
cout << arr[startRow][i] << ", ";
}startRow++;
}
}
cout << “END”;
}
int main()
{
int n, m;
cin >> n >> m;
int **arr = new int *[n];
for(int i = 0;i < n;i++){
arr[i] = new int[m];
for(int j = 0;j < m;j++){
cin >> arr[i][j];
}
}
spiral(arr, n, m);
return 0;
}
why are some test cases wrong ?
in my compiler all are running
