I have a matrix (n*n) which all its columns are ordered in non descending order while the rows are not ordered - I know that each value in a row is smaller than all the values in the rows below, but the values inside the rows are not sorted, although they are all either smaller or identical to the values in the row below.
I need to find a value in this matrix in O(n). I thought of running a binary search on one of the columns until I get into one cell which is the closest one to my searched value (in case, of course, I did not find the value during the search).
Then, I will check for the searched value in the row of the cell and in the row above (if cell > searched_val) or the row below (if cell < searched_val).
Will it work? Will it also work in case that the column is full with identical values?