pls go through my code and see where i am making mistake
Failing test case 0
Pls share your code so tht I could check it…
#include
using namespace std;
int main() {
int arr[10][10];
int r,c;
cin>>r>>c;
for(int i=0;i<r;i++)
{
for(int j=0;j<c;j++)
{
cin>>arr[i][j];
}
}
int startRow=0;
int endRow=r-1;
int startCol=0;
int endCol=c-1;
while(startRow<=endRow and startCol<=endCol)
{
//print startCol
for(int i=startRow;i<=endRow;i++)
{
cout<<arr[i][startCol]<<","<<" ";
}
startCol++;
//print endRow
for(int j=startCol;j<=endCol;j++)
{
cout<<arr[endRow][j]<<","<<" ";
}
endRow--;
//print endCol
if(startCol<endCol)
{
for(int j=endRow;j>=startRow;j--)
{
cout<<arr[j][endCol]<<","<<" ";
}
endCol--;
}
//print startRow
if(startRow<endRow)
{
for(int i=endCol;i>=startCol;i--)
{
cout<<arr[startRow][i]<<","<<" ";
}
startRow++;
}
}
cout<<"END";
return 0;
}
I have edited your code… Try to submit now…
1 Like