Showing segmentation fault in cpp code,can anybody help please?!


#1

int Solution::searchMatrix(vector<vector > &a, int b) {

int r=a.size(),c=a[0].size();
int k;
for(int i=0;i<r;i++)
{
    if(a[i][c-1]>=b) {k=i;break;}
}
int left=0,right=c-1;
while(right>=left)
{
    int mid=(left+right)/2;
    if(a[k][mid]==b) return 1;
    
    else if(a[k][mid]<b) left=mid+1;
    
    else right=mid-1;
}
return 0;