Why TLE in the following code?


#1

Why am i getting TLE in the following code?

int Solution::searchMatrix(vector<vector > &A, int B) {
int h1,l1;
int h2,l2;
int mid1,mid2;
int n=A.size();
int m=A[0].size();
l1=0;h1=n-1;l2=0;h2=m-1;
int mid;

while(l1<=h1 && l2<=h2){
    mid1=l1+(h1-l1)/2;
    mid2=l2+(h2-l2)/2;
    mid=A[mid1][mid2];
    if(mid==B){
        return 1;
    }
    if(mid>B){
        h1=mid1;
        h2=mid2;
    }
    else {
        l1=mid1;
        l2=mid2;
    }
    
}
return 0;

}