Spiral Print array

I have solved the question and i got the correct answer

but now i was trying to print the same thing using clockwise spiral print starting from the first row but i am getting the wrong answer can someone plz correct the code?

Example if i give n=3 m=4 and try printing first row->last col->last row->first col in clockwise manner i get the wrong answer for 2d array [[1,2,3,4],[5,6,7,8],[9,10,11,12]]

@aryamaan1011 please share the link where you are practicing the question or provide the whole code

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.