One test cass not passed did same as taught in video lec ,please reply quickly

#include <bits/stdc++.h>
using namespace std;
const int N = 1e4;
int mat[N][N];
int search2(int m, int n, int x)
{

int smallest = mat[0][0], largest = mat[n - 1][n - 1];
if (x < smallest || x > largest)
    return 0;

int i = 0, j = n - 1;
while (i < n && j >= 0)
{
    if (mat[i][j] == x)
    {
 
        return 1;
    }
    if (mat[i][j] > x)
        j--;
    else
        i++;
}

return 0;

}

int main()
{
int n, m;
cin >> n >> m;

for (int i = 0; i < n; i++)
{
    for (int j = 0; j < m; j++)
    {
        cin >> mat[i][j];
    }
}
int x;
cin >> x;
cout << search2(m, n, x);

return 0;

}

hi @mvarun975_a7021058d653891d updated and commented

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.