Something seems to be wrong but maybe logic seems to be correct please check it
@supratik260699 hey apke logic me thodi si dikkt hai ,apko top right element se start krna hai ,here is logic:
Let x = element we’re trying to search for in the matrix,
….e = current element we’re processing in the array.
- Start with top right element.
- 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) - repeat the i), ii) and iii) until you find the element or return false
Hope you get it,feel free to ask any doubt
Is this binary search?I have done it in linear search
@supratik260699 no ,its not binary search ,it is linear search ,read the logic you will get it ,apke wala hi logic hai but mene right top se start kia hai traversal .