Incorrect code of spiral matrix in your video

Your code is giving wrong output for testcase {[1,2,3],[4,5,6]}

Hello @anikcode,

You might have done some mistake in the code.
Please, share your code.


Above is my code

Hey @anikcode,

Yes, there is a slight mistake:
The if conditions inside the outer for loop should also check for equality i.e.:

  if(startRow<=endRow)
 {	//last row
  for(int i=endCol;i>=startCol;i--)
  {
  	cout<<a[endRow][i]<<" ";
  }
  endRow--;
 }

if(endCol>=startCol)
{ //first col
for(int i=endRow;i>=startRow;i–)
{
cout<<a[i][startCol]<<" ";
}
startCol++;
}

Hope, this would help.
Give a like if you are satisfied.

2 Likes

Yes thats what I am saying in video lecture this condition is not there.

hey @anikcode,

I would convey this to your mentor.
Thanks for pointing it out.

1 Like

Okay , thanks for resolving my doubt!

I hope I’ve cleared your doubt. I ask you to please rate your experience here
Your feedback is very important. It helps us improve our platform and hence provide you
the learning experience you deserve.

On the off chance, you still have some questions or not find the answers satisfactory, you may reopen
the doubt.