Can't figure out the problem inside it

My code did worked for test case 0, test case 1 and test case 3 I can’t figure out the possible reason why it is not running for test case 2…

your code is working only for square matrix not for rectangular matrix

You can refer my code as well

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.

umm the code which you sent is of clock wise and problem is of anticlock, and when i tried to add a rectangle matrix in my code of order 2,4 it was having one issue that it was printing the last number 2 times but i fixed it somehow by changing a loop of if(sr<=ec) to if(sr<ec) then it worked in test case 2 and test case 3 but failed test case 0 and test case 1

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.