Test Cases failed


Two test Cases are failed? Please tell me my mistake.

If you look carefully and try with different inputs you can see that your code works just fine for the input 4 but not for others. Which simply means your logic is correct but you have hard-coded some value
(If you haven’t tried with different inputs do give a check try with 5 and 6)

And it’s in the line 10 of your code, the if condition
if(j>=5-i && j<=3+i) //here you have written 5 and 3 which are hard-codes and works only for the input 4

To arrive at the solution is very simple. 5 is (rows +1) and 3 is (rows -1) make that change and it will work

see this

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.