Why my code not work in sample test case other cases passed successfully

#include<bits/stdc++.h>
using namespace std;

int main()
{
int n,m;
cin>>n>>m;
int a[n][m];

for(int i=0;i<n;i++)
{
    for(int j=0;j<m;j++)
    {
        cin>>a[i][j];
    }
}

int k;
cin>>k;

int x=a[0][0],y=a[n-1][m-1],i=0,j=m-1;
if(k<x||k>y)
    {
        cout<<"0"<<endl;
    }
while(i<n&&j>=0)
{
    if(a[i][j]==k)
    {
        cout<<"1";
        return 0;
    }
    if(a[i][j]>k)
    {
        j--;
    }
    if(a[i][j]<k)
    {
        i++;
    }
}
return 0;

}

hello @Gajesh-Namdeo-1171329206542221
what output u r getting for sample test case?

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.