A brute force O(n^2) should not be a problem at all.
A O(log(row_count * col_count) solution would be,
public bool func_name(int[][] input, int target) {
int row_num = input.length;
int col_num = input[0].length;
int b = 0, e = row_num * col_num - 1;
while(b <= e){
int m = (b + e) / 2;
int mid_value = input[m/col_num][m%col_num];
if( mid_value == target){
return true;
}else if(mid_value < target){
b = m+1;
}else{
e = m-1;
}
}
return false;
}
You could use a O(row_count+col_count) solution for which the steps would be.
intitalize row = 0 and coloumn as col_count-1
1.if input[row][coloumn]<target, increment row value.
2.If the value is greater decrement the coloumn value.