Unable to understand the problem with my code

The code that I have submitted provides the desired result in the appropriate format. In spite of that, my code is still failing in a few test cases. Kindly check my code for any mistake I may have made and provide me with the correct solution.

The error is in the condition if(sr<er) , which should be if(sr<=er) . It causes skipping the middle row or column. Your code is not working properly on 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.