Please tell in this


Is my approach correct in this question and also tell about the condition in the while loop.
I know there are errors, but I just wanna know the approach.

@cbcao263 hey your logic is not correct,use this algorithm:
Let x = element we’re trying to search for in the matrix,
….e = current element we’re processing in the array.

  1. Start with top right element.
  2. Loop: compare this element e with x
    …i) if e = x, then return position of e, since we found x in the given matrix.
    …ii) if e > x then move left to check elements smaller than e (if out of bound of matrix, then break and return false)
    …iii) if e < x then move below to check elements greater than e (if out of bound of matrix, then break and return false)
  3. repeat the i), ii) and iii) until you find the element or return false

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.