Test case 0 does not pass

#include
using namespace std;
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 startRow=0, endRow=n-1, startCol=0, endCol=m-1;

while(startCol <= endCol) {
	for(int i=startRow;i<=endRow;i++) {
		cout<<a[i][startCol]<<", ";
	}
	startCol++;
	for(int i=startCol;i<=endCol;i++) {
		cout<<a[endRow][i]<<", ";
	}
	endRow--;
	if(endCol > startCol) {
		for(int i=endRow; i>= startRow ; i--)
			cout<<a[i][endCol]<<", ";
		endCol--;
	}
	if(endRow > startRow) {
		for(int i=endCol; i>= startCol ; i--)
			cout<<a[startRow][i]<<", ";
		startRow++;
	}	
}
cout<<"END";

return 0;

}

@priyamthakuria27 when you are cheking if(endCol > startCol) check for equality too if(endCol>=startCol) similarly at second if condition if(endRow>= startRow)

did that. still doesn’t pass.

int terminating condition of while loop you are only cheking endCol>=startCol similarly you should check for startRow<=endRow. update this and your code will work fine

thank you.
it worked.

1 Like