I have done exactly same thing but my code is not passing all the test cases o hacker block, may ik my error

#include
using namespace std;
int main() {
int m,n;
cin>>m>>n;
int a[m][n];
for(int i=0;i<m;i++)
{
for(int j=0;j<n;j++)
{
cin>>a[i][j];
}
}
int sr=0;
int sc=0;
int er=m-1;
int ec=n-1;
while(sr<=er and sc<=ec)
{
for(int i= sc;i<=ec;i++)
cout<<a[sr][i]<<" “;
sr++;
for(int i= sr;i<=er;i++)
cout<<a[i][ec]<<” “;
ec–;
if(er>sr)
{for(int i= ec;i>=sc;i–)
cout<<a[er][i]<<” “;
er–;}
if(ec>sc)
{for(int i= er;i>=sr;i–)
cout<<a[i][sc]<<” ";
sc++;
}

}

return 0;

}

hello @ganesh2512

use >= in place of > in above if statements

but in lecture, bhaiya told to use >. >= is covered in while loop

if u will use > , then some row /column might remain unprinted

yes that worked on hacker block, but I in video it was taught different

also see second soln in this link

which link ?

yeah whats the issue?

here also in soln 2, it says <, not<=

thier m is not pointing to last column , it is pointing next index of last column thats why they are using < and not <=

are you getting my doubt, in video ,bhaiya used >,not >=,same at gfg

are u reading my replies? gfg code is not same as urs.
dry run on small test cases and spot the difference.

got it, thankyou, your replies were not visible here,just saw them at mail

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.