Failed test cases

#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

hello @ayushi1150 corrected code https://ide.codingblocks.com/s/337907.
if you have any doubt please let me know .
if you feel your diubt is cleared please mark this as resolved.
Happy Learning !!

sorry for late reply but sir your output is not matching it is giving the spiral form not anti spiral form

I am getting wrong test cases

Here it should be endcol>=startcol

Here it should be endrow>=start row

If it still not work then please share your code in coding blocks IDE

Sir i am still getting 1 test case wrong

Share ur code in IDE so that i can debug

Hey @ayushi1150
Issue on line 29

  if(endRow >= startRow){

Please mark it as resolved if u don’t have any other doubt in this :slight_smile: