my code is giving same output as given for test case 0, but it is not accepting, where is problem ?
int startRow=0,startCol=0,endRow=m-1,endCol=n-1;
while(startCol <= endCol) {
// Printing first column
for(int i=startRow; i<=endRow; i++) cout<<a[i][startCol]<<", ";
startCol++;
// Printing last row
for(int j=startCol; j<=endCol; j++) cout<<a[endRow][j]<<", ";
endRow--;
// Printing last column if startCol < endCol
if(startCol < endCol) {
for(int i=endRow; i>=startRow; i--) cout<<a[i][endCol]<<", ";
endCol--;
}
// Printing first row if startRow < endRow
if(startRow < endRow) {
for(int j=endCol; j>=startCol; j--) cout<<a[startRow][j]<<", ";
startRow++;
}
}
cout<<"END"<<endl;