Hi I am getting TLE for this code. Can you please suggest what changes should I make

#include
using namespace std;
int main() {

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

int f=0;
int i=n-1;//column
int j=0;//row
while(i>=0&&j<m)
{
	if(ar[j][i]==key)
	{
		f=1;
		
	}
	else if(key>ar[j][i])
	{
		j++;
	}
	else if(key<ar[j][i])
	{
		i--;
	}
}
cout<<f;
	return 0;

}

Hello @suhaib0900 use break statement after you ae doing f=1.

check this;

Got it. Thanks. You can close the thread.

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.